'profile widget widget_banner_post', 'description' => esc_html__( 'Display banner section', 'bike-shop' ) ); parent::__construct( 'banner_post', esc_html__( 'Bike Shop : Header Banner', 'bike-shop' ), $widget_ops ); } /** * Helper function that holds widget fields * Array is used in update and form functions */ private function widget_fields() { $fields = array( 'banner_img' => array( 'bike_shop_widgets_name' => 'banner_img', 'bike_shop_widgets_title' => esc_html__( 'Banner Image ( use 2560X624 px for best result)', 'bike-shop' ), 'bike_shop_widgets_field_type' => 'upload' ), 'banner_top_text' => array( 'bike_shop_widgets_name' => 'banner_top_text', 'bike_shop_widgets_title' => esc_html__( 'Banner top text', 'bike-shop' ), 'bike_shop_widgets_field_type' => 'text' ), 'banner_bottom_text' => array( 'bike_shop_widgets_name' => 'banner_bottom_text', 'bike_shop_widgets_title' => esc_html__( 'Banner Bottom Text', 'bike-shop' ), 'bike_shop_widgets_field_type' => 'text' ), 'banner_link' => array( 'bike_shop_widgets_name' => 'banner_link', 'bike_shop_widgets_title' => esc_html__( 'Banner link', 'bike-shop' ), 'bike_shop_widgets_field_type' => 'url' ), 'banner_link_text' => array( 'bike_shop_widgets_name' => 'banner_link_text', 'bike_shop_widgets_title' => esc_html__( 'Banner Link Text', 'bike-shop' ), 'bike_shop_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 ); if( empty( $instance ) ) { return ; } $bike_shop_banner_img = empty( $instance['banner_img'] ) ? '' : $instance['banner_img']; $bike_shop_banner_top_text = empty( $instance['banner_top_text'] ) ? '' : $instance['banner_top_text']; $bike_shop_banner_bottom_text = empty( $instance['banner_bottom_text'] ) ? '' : $instance['banner_bottom_text']; $bike_shop_banner_link_text = empty( $instance['banner_link_text'] ) ? '' : $instance['banner_link_text']; $bike_shop_banner_link = empty( $instance['banner_link'] ) ? '' : $instance['banner_link']; if( !empty( $bike_shop_section_title ) ) { $sec_title_class = 'has-title'; } else { $sec_title_class = 'no-title'; } 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[$bike_shop_widgets_name] = bike_shop_widgets_updated_field_value( $widget_field, $new_instance[$bike_shop_widgets_name] ); } return $instance; } /** * Back-end widget form. * * @see WP_Widget::form() * * @param array $instance Previously saved values from database. * * @uses bike_shop_widgets_show_widget_field() defined in article-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 ); $bike_shop_widgets_field_value = !empty( $instance[$bike_shop_widgets_name] ) ? wp_kses_post( $instance[$bike_shop_widgets_name] ) : ''; bike_shop_widgets_show_widget_field( $this, $widget_field, $bike_shop_widgets_field_value ); } } }