/>
Checking this option will automatically replace all audio players rendered with the default [audio] shortcode
'',
'src' => '',
'loop' => '',
'autoplay' => '',
'preload' => '',
'class' => '',
'id' => sprintf( 'audio-%d-%d', $post_id, $instances ),
'style' => 'width: 100%'
),
$atts
);
// Clammr It only supports mp3s.
// Check either the "mp3" attribute or the "src" for a valid mp3 file
$mp3 = $args['mp3'];
$src = $args['src'];
if($mp3 == "" && $src != "") {
if($this->endsWith(strtolower($src), ".mp3")) {
$mp3 = $src;
}
}
// continue using default WP player if it's not an mp3
if($mp3 == "") {
return wp_audio_shortcode($atts);
}
// These ones should just be omitted altogether if they are blank
foreach ( array( 'loop', 'autoplay', 'preload' ) as $a ) {
if ( empty( $atts[$a] ) )
unset( $atts[$a] );
}
unset( $atts['mp3'] );
unset( $atts['src'] );
$attr_strings = array();
foreach ( $atts as $k => $v ) {
$attr_strings[] = $k . '="' . esc_attr( $v ) . '"';
}
$imageUrl = $this->get_post_imageUrl(get_the_ID());
$title = get_the_title();
$html = sprintf( '', join( ' ', $attr_strings ) );
return $html;
}
public function endsWith($haystack, $needle) {
$length = strlen($needle);
if ($length == 0) {
return true;
}
return (substr($haystack, -$length) === $needle);
}
public function setupHeader() {
// Initialize GA
$initGA = "";
$initGA .= "";
echo $initGA;
}
public function setupFooter() {
// Initialize the players
$initplayers = "";
$initplayers .= "";
echo $initplayers;
}
public function addScripts() {
wp_register_style( 'clammr-player-style', plugins_url('/css/clammr-audio-player.css', __FILE__) );
wp_enqueue_style( 'clammr-player-style' );
wp_enqueue_style( 'wp-mediaelement' );
wp_enqueue_script('clammr-player-script', plugins_url( '/js/clammr-audio-player.js' , __FILE__ ), array('jquery', 'wp-mediaelement') );
wp_register_script('google-analytics', get_stylesheet_directory_uri() . '/google_analytics_object.js',
false,
'1.0',
true
);
wp_enqueue_script( 'google-analytics' );
}
function get_post_imageUrl( $postID ) {
$args = array(
'numberposts' => 1,
'order' => 'ASC',
'post_mime_type' => 'image',
'post_parent' => $postID,
'post_status' => null,
'post_type' => 'attachment',
);
$attachments = get_children( $args );
$imageUrlToReturn = "";
$biggestArea = 0;
if ( $attachments ) {
// returns the biggest image in this post
foreach ( $attachments as $attachment_id => $attachment ) {
$image_attributes = wp_get_attachment_image_src( $attachment_id, 'full' );
$url = $image_attributes[0];
$width = $image_attributes[1];
$height = $image_attributes[2];
$area = $width * $height;
if( $area > $biggestArea ) {
$biggestArea = $area;
$imageUrlToReturn = $url;
}
}
}
return $imageUrlToReturn;
}
}
// Instantiate our class
$ClammrPlayer = ClammrPlayer::getInstance();
function clammrplayer_install() {
$option = get_option('powerpress_clammr'); // will be either 0 or 1 if its been configured
if( $option == '' ) // if empty (never configured)
update_option('powerpress_clammr', 1); // Enable, the setting was never configured
}
add_action('activate_audio-player-by-clammr/clammr-audio-player.php', 'clammrplayer_install');