/>
Checking this option will automatically replace all audio players rendered with the default [audio] shortcode
'',
'src' => '',
'loop' => '',
'autoplay' => '',
'preload' => 'none'
);
$atts = shortcode_atts( $defaults_atts, $attr, 'audio' );
// Clammr It only supports mp3s.
// Check either the "mp3" attribute or the "src" for a valid mp3 file
$mp3 = $atts['mp3'];
$src = $atts['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);
}
$html_atts = array(
'id' => sprintf( 'audio-%d-%d', $post_id, $instances ),
'loop' => wp_validate_boolean( $atts['loop'] ),
'autoplay' => wp_validate_boolean( $atts['autoplay'] ),
'preload' => $atts['preload'],
'style' => 'width: 100%; visibility: hidden;',
);
// These ones should just be omitted altogether if they are blank
foreach ( array( 'loop', 'autoplay', 'preload' ) as $a ) {
if ( empty( $html_atts[$a] ) ) {
unset( $html_atts[$a] );
}
}
$attr_strings = array();
foreach ( $html_atts as $k => $v ) {
$attr_strings[] = $k . '="' . esc_attr( $v ) . '"';
}
$imageUrl = $this->get_post_imageUrl(get_the_ID());
$title = get_the_title();
$html = sprintf( '', esc_attr( $title ), $imageUrl, join(' ', $attr_strings), $mp3);
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') );
}
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');