__( 'Display media (video/slideshow) widget, support many sites including YouTube, Vimeo, Flickr, etc.', 'adsoft_language' ) ) ); } /** * Helper function that holds widget fields * Array is used in update and form functions */ private function widget_fields() { $fields = array( // Title 'widget_title' => array( 'adsoft_widgets_name' => 'widget_title', 'adsoft_widgets_title' => __( 'Title', 'adsoft_language' ), 'adsoft_widgets_field_type' => 'text' ), // Other fields 'embed_url' => array ( 'adsoft_widgets_name' => 'embed_url', 'adsoft_widgets_title' => __( 'Embed URL', 'adsoft_language' ), 'adsoft_widgets_field_type' => 'text' ), 'embed_width' => array ( 'adsoft_widgets_name' => 'embed_width', 'adsoft_widgets_title' => __( 'Embed width in pixels', 'adsoft_language' ), 'adsoft_widgets_field_type' => 'number' ), 'embed_description' => array ( 'adsoft_widgets_name' => 'embed_description', 'adsoft_widgets_title' => __( 'Description', 'adsoft_language' ), 'adsoft_widgets_field_type' => 'textarea', 'adsoft_widgets_allowed_tags' => '' ), ); return $fields; } /** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget( $args, $instance ) { extract( $args ); $widget_title = apply_filters( 'widget_title', $instance['widget_title'] ); $embed_url = $instance['embed_url']; $embed_width = $instance['embed_width']; $embed_description = $instance['embed_description']; echo $before_widget; ?>
'; // Check if user entered embed width if( isset( $embed_width ) && $embed_width > 0 ) { echo wp_oembed_get( $embed_url, array( 'width' => $embed_width ) ); } else { echo wp_oembed_get( $embed_url ); } echo '
'; } if( isset( $embed_description ) ) { echo '
' . $embed_description . '
'; } ?> widget_fields(); // Loop through fields foreach( $widget_fields as $widget_field ) { extract( $widget_field ); // Use helper function to get updated field values $instance[$adsoft_widgets_name] = adsoft_widgets_updated_field_value( $widget_field, $new_instance[$adsoft_widgets_name] ); echo $instance[$adsoft_widgets_name]; } return $instance; } /** * Back-end widget form. * * @see WP_Widget::form() * * @param array $instance Previously saved values from database. * * @uses adsoft_widgets_show_widget_field() defined in widget-fields.php */ public function form( $instance ) { $widget_fields = $this->widget_fields(); // Loop through fields foreach( $widget_fields as $widget_field ) { // Make array elements available as variables extract( $widget_field ); $adsoft_widgets_field_value = isset( $instance[$adsoft_widgets_name] ) ? esc_attr( $instance[$adsoft_widgets_name] ) : ''; adsoft_widgets_show_widget_field( $this, $widget_field, $adsoft_widgets_field_value ); } } }