'bike-shop-widget bike_shop_category_products', 'description' => esc_html__( 'Display products in slider from selected category.', 'bike-shop' ), 'customize_selective_refresh' => true, ); parent::__construct( 'bike_shop_product_slider', esc_html__( 'Bike Shop: Display Products in slider by Category', 'bike-shop' ), $widget_ops ); } /** * Helper function that holds widget fields * Array is used in update and form functions */ private function widget_fields() { $fields = array( 'productslider_title' => array( 'bike_shop_widgets_name' => 'productslider_title', 'bike_shop_widgets_title' => esc_html__( 'Widget title', 'bike-shop' ), 'bike_shop_widgets_field_type' => 'text' ), 'productslider_category_id' => array( 'bike_shop_widgets_name' => 'productslider_category_id', 'bike_shop_widgets_title' => esc_html__( 'Product Category', 'bike-shop' ), 'bike_shop_widgets_field_type' => 'select', 'bike_shop_widgets_field_options' => bike_shop_product_categories_dropdown() ), 'productslider_post_count' => array( 'bike_shop_widgets_name' => 'productslider_post_count', 'bike_shop_widgets_title' => esc_html__( 'Post Count', 'bike-shop' ), 'bike_shop_widgets_default' => '5', 'bike_shop_widgets_field_type' => 'number' ), 'category_product_enable_slider' => array( 'bike_shop_widgets_name' => 'category_product_enable_slider', 'bike_shop_widgets_title' => esc_html__( 'Enable Slider', 'bike-shop' ), 'bike_shop_widgets_default' => true, 'bike_shop_widgets_field_type' => 'checkbox' ), ); 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_widget_title = empty( $instance['productslider_title'] ) ? '' : $instance['productslider_title']; $bike_shop_product_cat_id = empty( $instance['productslider_category_id'] ) ? '' : $instance['productslider_category_id']; $bike_shop_post_count = empty( $instance['productslider_post_count'] ) ? '5' : $instance['productslider_post_count']; $bike_shop_post_enable_slider = empty( $instance['category_product_enable_slider'] ) ? '' : $instance['category_product_enable_slider']; echo $before_widget; ?>