esc_html__( 'Displays your Flickr photos.', 'biru' ) ) ); } /** * Helper function that holds widget fields * Array is used in update and form functions */ private function widget_fields() { $fields = array( // Title 'widget_title' => array( 'biru_widgets_name' => 'widget_title', 'biru_widgets_title' => esc_html__( 'Title', 'biru' ), 'biru_widgets_field_type' => 'text' ), // Other fields 'flickr_id' => array ( 'biru_widgets_name' => 'flickr_id', 'biru_widgets_title' => esc_html__( 'Flickr ID', 'biru' ), 'biru_widgets_field_type' => 'text' ), 'photo_count' => array ( 'biru_widgets_name' => 'photo_count', 'biru_widgets_title' => esc_html__( 'Number of Photos', 'biru' ), 'biru_widgets_field_type' => 'select', 'biru_widgets_field_options' => array( '4' => '4', '8' => '8', '12' => '12', '16' => '16', ) ), 'photo_type' => array ( 'biru_widgets_name' => 'photo_type', 'biru_widgets_title' => esc_html__( 'Type (user or group)', 'biru' ), 'biru_widgets_field_type' => 'select', 'biru_widgets_field_options' => array( 'user' => 'User', 'group' => 'Group' ) ), 'photo_display' => array ( 'biru_widgets_name' => 'photo_display', 'biru_widgets_title' => esc_html__( 'Display', 'biru' ), 'biru_widgets_field_type' => 'select', 'biru_widgets_field_options' => array( 'latest' => 'Latest', 'random' => 'Random' ) ) ); 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'] ); $flickr_id = strip_tags( $instance['flickr_id'] ); $photo_count = $instance['photo_count']; $photo_type = $instance['photo_type']; $photo_display = $instance['photo_display']; echo $before_widget; // Show title if( isset( $widget_title ) ) { echo $before_title . $widget_title . $after_title; } ?>
widget_fields(); // Loop through fields foreach( $widget_fields as $widget_field ) { extract( $widget_field ); // Use helper function to get updated field values $instance[$biru_widgets_name] = biru_widgets_updated_field_value( $widget_field, $new_instance[$biru_widgets_name] ); echo $instance[$biru_widgets_name]; } return $instance; } /** * Back-end widget form. * * @see WP_Widget::form() * * @param array $instance Previously saved values from database. * * @uses biru_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 ); $biru_widgets_field_value = isset( $instance[$biru_widgets_name] ) ? esc_attr( $instance[$biru_widgets_name] ) : ''; biru_widgets_show_widget_field( $this, $widget_field, $biru_widgets_field_value ); } } }