/var/www/(Del)hsihk.com/wp-content/plugins/woocommerce/includes/abstracts/abstract-wc-widget.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
/**
 * Abstract Widget Class
 *
 * @author      WooThemes
 * @category    Widgets
 * @package     WooCommerce/Abstracts
 * @version     2.1.0
 * @extends     WP_Widget
 */
abstract class WC_Widget extends WP_Widget {

    public 
$widget_cssclass;
    public 
$widget_description;
    public 
$widget_id;
    public 
$widget_name;
    public 
$settings;

    
/**
     * Constructor
     */
    
public function __construct() {

        
$widget_ops = array(
            
'classname'   => $this->widget_cssclass,
            
'description' => $this->widget_description
        
);

        
$this->WP_Widget$this->widget_id$this->widget_name$widget_ops );

        
add_action'save_post', array( $this'flush_widget_cache' ) );
        
add_action'deleted_post', array( $this'flush_widget_cache' ) );
        
add_action'switch_theme', array( $this'flush_widget_cache' ) );
    }

    
/**
     * get_cached_widget function.
     */
    
function get_cached_widget$args ) {

        
$cache wp_cache_getapply_filters'woocommerce_cached_widget_id'$this->widget_id ), 'widget' );

        if ( ! 
is_array$cache ) ) {
            
$cache = array();
        }

        if ( isset( 
$cache$args['widget_id'] ] ) ) {
            echo 
$cache$args['widget_id'] ];
            return 
true;
        }

        return 
false;
    }

    
/**
     * Cache the widget
     * @param string $content
     */
    
public function cache_widget$args$content ) {
        
$cache$args['widget_id'] ] = $content;

        
wp_cache_setapply_filters'woocommerce_cached_widget_id'$this->widget_id ), $cache'widget' );
    }

    
/**
     * Flush the cache
     *
     * @return void
     */
    
public function flush_widget_cache() {
        
wp_cache_deleteapply_filters'woocommerce_cached_widget_id'$this->widget_id ), 'widget' );
    }

    
/**
     * update function.
     *
     * @see WP_Widget->update
     * @param array $new_instance
     * @param array $old_instance
     * @return array
     */
    
public function update$new_instance$old_instance ) {

        
$instance $old_instance;

        if ( ! 
$this->settings ) {
            return 
$instance;
        }

        foreach ( 
$this->settings as $key => $setting ) {

            if ( isset( 
$new_instance$key ] ) ) {
                
$instance$key ] = sanitize_text_field$new_instance$key ] );
            } elseif ( 
'checkbox' === $setting['type'] ) {
                
$instance$key ] = 0;
            }
        }

        
$this->flush_widget_cache();

        return 
$instance;
    }

    
/**
     * form function.
     *
     * @see WP_Widget->form
     * @param array $instance
     */
    
public function form$instance ) {

        if ( ! 
$this->settings ) {
            return;
        }

        foreach ( 
$this->settings as $key => $setting ) {

            
$value   = isset( $instance$key ] ) ? $instance$key ] : $setting['std'];

            switch ( 
$setting['type'] ) {

                case 
"text" :
                    
?>
                    <p>
                        <label for="<?php echo $this->get_field_id$key ); ?>"><?php echo $setting['label']; ?></label>
                        <input class="widefat" id="<?php echo esc_attr$this->get_field_id$key ) ); ?>" name="<?php echo $this->get_field_name$key ); ?>" type="text" value="<?php echo esc_attr$value ); ?>" />
                    </p>
                    <?php
                
break;

                case 
"number" :
                    
?>
                    <p>
                        <label for="<?php echo $this->get_field_id$key ); ?>"><?php echo $setting['label']; ?></label>
                        <input class="widefat" id="<?php echo esc_attr$this->get_field_id$key ) ); ?>" name="<?php echo $this->get_field_name$key ); ?>" type="number" step="<?php echo esc_attr$setting['step'] ); ?>" min="<?php echo esc_attr$setting['min'] ); ?>" max="<?php echo esc_attr$setting['max'] ); ?>" value="<?php echo esc_attr$value ); ?>" />
                    </p>
                    <?php
                
break;

                case 
"select" :
                    
?>
                    <p>
                        <label for="<?php echo $this->get_field_id$key ); ?>"><?php echo $setting['label']; ?></label>
                        <select class="widefat" id="<?php echo esc_attr$this->get_field_id$key ) ); ?>" name="<?php echo $this->get_field_name$key ); ?>">
                            <?php foreach ( $setting['options'] as $option_key => $option_value ) : ?>
                                <option value="<?php echo esc_attr$option_key ); ?><?php selected$option_key$value ); ?>><?php echo esc_html$option_value ); ?></option>
                            <?php endforeach; ?>
                        </select>
                    </p>
                    <?php
                
break;

                case 
"checkbox" :
                    
?>
                    <p>
                        <input id="<?php echo esc_attr$this->get_field_id$key ) ); ?>" name="<?php echo esc_attr$this->get_field_name$key ) ); ?>" type="checkbox" value="1" <?php checked$value); ?> />
                        <label for="<?php echo $this->get_field_id$key ); ?>"><?php echo $setting['label']; ?></label>
                    </p>
                    <?php
                
break;
            }
        }
    }
}