PluginProbe
Filter Everything — WordPress & WooCommerce Filters / trunk
Filter Everything — WordPress & WooCommerce Filters vtrunk
1.9.6 1.9.5 1.9.4 1.9.3 1.9.2.2 1.9.2.1 trunk 1.2.1 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.4.1 1.4.4 1.4.5 1.4.8 1.4.9 1.5.0 1.5.1 1.6.0 1.6.1 1.6.2 1.6.3 All 51 releases
filter-everything / src / Admin / Widgets / ChipsWidget.php

ChipsWidget.php in Filter Everything — WordPress & WooCommerce Filters trunk, at src/Admin/Widgets/ChipsWidget.php

97 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 namespace FilterEverything\Filter;
5
6 if ( ! defined('ABSPATH') ) {
7 exit;
8 }
9 class ChipsWidget extends \WP_Widget
10 {
11 public function __construct() {
12 parent::__construct(
13 'wpc_chips_widget', // Base ID
14 esc_html__( 'Filter Everything &mdash; Chips', 'filter-everything'),
15 array( 'description' => esc_html__( 'Displays selected terms', 'filter-everything' ), )
16 );
17 }
18
19 /**
20 * Front-end display of widget.
21 *
22 * @see WP_Widget::widget()
23 *
24 * @param array $args Widget arguments.
25 * @param array $instance Saved values from database.
26 */
27 public function widget( $args, $instance ) {
28 $title = isset( $instance['title'] ) ? $instance['title'] : '';
29 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
30 $set_id = isset( $instance['set_id'] ) ? preg_replace('/[^\d\,]?/', '', $instance['set_id'] ) : '';
31 $mobile = ( !empty( $instance['mobile'] ) ) ? $instance['mobile'] : '';
32 $setIds = $classes = [];
33
34 if( isset( $_POST['action'] ) && $_POST['action'] === 'elementor_ajax' ){
35 echo '<strong>'.esc_html__( 'Filter Everything &mdash; Chips', 'filter-everything' ).'</strong>';
36 return;
37 }
38
39 if( isset( $_GET['action'] ) && $_GET['action'] === 'elementor' ){
40 echo '<strong>'.esc_html__( 'Filter Everything &mdash; Chips', 'filter-everything' ).'</strong>';
41 return;
42 }
43
44 if( $mobile ){
45 $classes[] = 'wpc-show-on-mobile';
46 if( strpos($args['before_title'], 'widget-title') !== false ){
47 $args['before_title'] = str_replace('widget-title', 'widget-title wpc-show-on-mobile-widget-title', $args['before_title']);
48 } elseif( strpos($args['before_title'], 'widgettitle') !== false ){
49 $args['before_title'] = str_replace('widgettitle', 'widgettitle wpc-show-on-mobile-widget-title', $args['before_title']);
50 }
51 }
52
53 if( $set_id ){
54 $setIds = explode( ",", $set_id );
55 }
56
57 echo $args['before_widget'];
58 if ( ! empty( $title ) ) {
59 echo $args['before_title'] . $title . $args['after_title'];
60 }
61
62 flrt_show_selected_terms(true, $setIds, $classes);
63
64 echo $args['after_widget'];
65 }
66
67 public function form( $instance ) {
68
69 $title = isset( $instance['title'] ) ? $instance['title'] : '';
70 $set_id = isset( $instance['set_id'] ) ? $instance['set_id'] : '';
71 $mobile = isset( $instance['mobile'] ) ? (bool) $instance['mobile'] : true;
72
73 ?>
74 <p>
75 <label for="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>"><?php esc_html_e( 'Title:' ); ?></label>
76 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
77 </p>
78 <p>
79 <label for="<?php echo esc_attr( $this->get_field_id( 'set_id' ) ); ?>"><?php esc_html_e( 'Show Chips only for Set with IDs:', 'filter-everything' ); ?></label>
80 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'set_id' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'set_id' ) ); ?>" type="text" value="<?php echo esc_attr( $set_id ); ?>" placeholder="<?php esc_html_e( 'e.g. 2745, 324', 'filter-everything' ); ?>"/>
81 </p>
82 <p>
83 <input type="checkbox" class="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'mobile' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'mobile' ) ); ?>"<?php checked( $mobile ); ?> />
84 <label for="<?php echo esc_attr( $this->get_field_id( 'mobile' ) ); ?>"><?php esc_html_e( 'Show on mobile', 'filter-everything' ); ?></label>
85 </p>
86 <?php
87 }
88
89 public function update( $new_instance, $old_instance ) {
90 $instance = [];
91 $instance['title'] = ( !empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
92 $instance['set_id'] = ( !empty( $new_instance['set_id'] ) ) ? $new_instance['set_id'] : '';
93 $instance['mobile'] = ( !empty( $new_instance['mobile'] ) ) ? 1 : 0;
94
95 return $instance;
96 }
97 }