'A widget to display the audio files, which have been attached to a page or post')); } /** @see WP_Widget::widget */ public function widget( $args, $instance ) { extract($args); // tmp checking please remove print_r($args); global $wpdb, $post; // add an array to add the mime types to after we check which user options have been selected. $mime_type_array = array(); $title = apply_filters( 'widget_title', $instance['title'] ); $limit = $instance['limit']; // NEW // Allowed audio mime types list (mpeg, ogg, wav) $opt_mpeg = $instance['mpeg_audio']; $opt_ogg = $instance['ogg_audio']; $opt_wav = $instance['wav_audio']; $opt_order_ascending = $instance['order_ascending']; $opt_description = $instance['doc_description']; $opt_hide_sidebar = $instance['hide_sidebar']; // Check to see what mime types the widget should display. if($opt_mpeg == '1'): array_push($mime_type_array, "'audio/mpeg'"); else: array_push($mime_type_array, "' '"); endif; if($opt_ogg == '1'): array_push($mime_type_array, "'audio/ogg'"); else: array_push($mime_type_array, "' '"); endif; if($opt_wav == '1'): array_push($mime_type_array, "'audio/wav'"); else: array_push($mime_type_array, "' '"); endif; // build list of mime types as a string to use within the db query $mime_type_str = implode(", ", $mime_type_array); if(isset($showresults)): $quick_check = count($showresults); if(!$quick_check ==0){ echo $before_widget; } endif; if($limit == 0): $limit=1; endif; if ( $title ): $post_id = $post->ID; // check to see if post id is set. if($opt_order_ascending==0): $order = 'DESC'; else: $order = 'ASC'; endif; if(isset($post_id)): // Query the post table to find all attachment items related to the post parent ID $showresults = $wpdb->get_results("SELECT * FROM `{$wpdb->prefix}posts` WHERE post_type = 'attachment' AND post_mime_type IN ($mime_type_str) AND post_parent = $post_id ORDER BY post_title $order LIMIT $limit"); endif; // check to see if there are any attachment documents found in the database. if(isset($showresults)): $quick_check = count($showresults); if(!$quick_check ==0){ if(isset($args['id'])) : if (isset($opt_hide_sidebar)): if($opt_hide_sidebar == '0'): echo ''; endif; endif; endif; } endif; endif; if(isset($showresults)): $quick_check = count($showresults); if(!$quick_check ==0){ echo $after_widget; } endif; } /** @see WP_Widget::update */ function update( $new_instance, $old_instance ) { $instance = $old_instance; $new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '','limit' => '','mpeg_audio' => '','ogg_audio' => '','wav_audio' => '','order_ascending' => '','doc_description' => '','hide_sidebar' => '') ); $instance['title'] = strip_tags($new_instance['title']); $instance['limit'] = strip_tags($new_instance['limit']); // NEW $instance['mpeg_audio'] = $new_instance['mpeg_audio'] ? 1 : 0; $instance['ogg_audio'] = $new_instance['ogg_audio'] ? 1 : 0; $instance['wav_audio'] = $new_instance['wav_audio'] ? 1 : 0; $instance['order_ascending'] = $new_instance['order_ascending'] ? 1 : 0; $instance['doc_description'] = $new_instance['doc_description'] ? 1 : 0; $instance['hide_sidebar'] = $new_instance['hide_sidebar'] ? 1 : 0; return $instance; } /** @see WP_Widget::form */ function form( $instance ) { if ( $instance ) { $instance = wp_parse_args( (array) $instance, array( 'title' => '','limit' => '','mpeg_audio' => '','ogg_audio' => '','wav_audio' => '','order_ascending' => '','doc_description' => '', 'hide_sidebar' => '') ); $title = esc_attr($instance['title']); // NEW $limit = $instance['limit']; // NEW $opt_mpeg = $instance['mpeg_audio'] ? 'checked="checked"' : ''; $opt_ogg = $instance['ogg_audio'] ? 'checked="checked"' : ''; $opt_wav = $instance['wav_audio'] ? 'checked="checked"' : ''; $opt_order_ascending = $instance['order_ascending'] ? 'checked="checked"' : ''; $opt_description = $instance['doc_description'] ? 'checked="checked"' : ''; $opt_hide_sidebar = $instance['hide_sidebar'] ? 'checked="checked"' : ''; } else { $title = 'Audio attachments'; $limit = '20'; $opt_mpeg = ''; $opt_ogg = ''; $opt_wav = ''; $opt_order_ascending = ''; $opt_description = ''; $opt_hide_sidebar = ''; } echo '
Select audio file types,
which are allowed to be displayed, only MPEG files are supported by the player. Any other audio type can only be added as a download item:
Hide the widget from the sidebar:
Order the list in an ascending order :
Display the files description text: