'audioplayer', 'description' => 'A widget that embeds an audio player. Requires the audio-player plugin.'); /* Widget control settings. */ $control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'audioplayer-widget' ); /* Create the widget. */ $this->WP_Widget( 'audioplayer-widget', 'Audio', $widget_ops, $control_ops ); } /* * Displays the widget on the screen. */ function widget( $args, $instance ) { extract( $args ); /* load the label and URL from the widget settings. */ $title = apply_filters('widget_title', $instance['title'] ); $audioUri = $instance['audioUri']; /* Before widget (defined by themes). */ echo $before_widget; /* Display the widget title if one was specified. */ if ( $title ) echo $before_title . $title . $after_title; /* Display the audio file from widget settings if it was specified. Note that if the audio-player plugin is not present nothing is displayed. */ if ( $audioUri ) { if (function_exists("insert_audio_player")) { insert_audio_player(sprintf("[audio:%1s]", $audioUri) ); } } /* any content required after a widget(for theme support). */ echo $after_widget; } /* * Save the settings. */ function update( $new_instance, $old_instance ) { $instance = $old_instance; /* Strip tags for title and name to remove HTML (important for text inputs). */ $instance['title'] = strip_tags( $new_instance['title'] ); $instance['audioUri'] = strip_tags( $new_instance['audioUri'] ); return $instance; } /* * Displays the widget settings controls on the widget panel. */ function form( $instance ) { /* Set up some default widget settings. */ $defaults = array( 'title' => 'Label', 'audioUri' => 'http://domain.com/audio/file.mp3' ); $instance = wp_parse_args( (array) $instance, $defaults ); ?>