esc_html__('This widget show banner with title, description and link', 'buzstores') ) ); } /** * Helper function that holds widget fields * Array is used in update and form functions */ private function widget_fields() { $fields = array( 'banner_title' => array( 'buzstores_widgets_name' => 'banner_title', 'buzstores_widgets_title' => esc_html__('Title', 'buzstores'), 'buzstores_widgets_field_type' => 'text', ), 'banner_image' => array( 'buzstores_widgets_name' => 'banner_image', 'buzstores_widgets_title' => esc_html__('Banner Image', 'buzstores'), 'buzstores_widgets_field_type' => 'upload', ), 'button_text' => array( 'buzstores_widgets_name' => 'button_text', 'buzstores_widgets_title' => esc_html__('Button Text', 'buzstores'), 'buzstores_widgets_field_type' => 'text', ), 'button_link' => array( 'buzstores_widgets_name' => 'button_link', 'buzstores_widgets_title' => esc_html__('Button Link', 'buzstores'), 'buzstores_widgets_field_type' => 'text', ), ); 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); $banner_image = isset( $instance['banner_image'] ) ? $instance['banner_image'] : '' ; $button_text = isset( $instance['button_text'] ) ? $instance['button_text'] : '' ; $button_link = isset( $instance['button_link'] ) ? $instance['button_link'] : '' ; $title_widget = apply_filters( 'widget_title', empty( $instance['banner_title'] ) ? '' : $instance['banner_title'], $instance, $this->id_base ); echo $before_widget; ?> widget_fields(); // Loop through fields foreach ($widget_fields as $widget_field) { extract($widget_field); // Use helper function to get updated field values $instance[$buzstores_widgets_name] = buzstores_widgets_updated_field_value($widget_field, $new_instance[$buzstores_widgets_name]); } return $instance; } /** * Back-end widget form. * * @see WP_Widget::form() * * @param array $instance Previously saved values from database. * * @uses buzstores_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); $buzstores_widgets_field_value = !empty($instance[$buzstores_widgets_name]) ? esc_attr($instance[$buzstores_widgets_name]) : ''; buzstores_widgets_show_widget_field($this, $widget_field, $buzstores_widgets_field_value); } } }