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3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / includes / abstracts / abstract-wc-widget.php
woocommerce / includes / abstracts Last commit date
abstract-wc-data.php 5 years ago abstract-wc-deprecated-hooks.php 6 years ago abstract-wc-integration.php 5 years ago abstract-wc-log-handler.php 5 years ago abstract-wc-object-query.php 5 years ago abstract-wc-order.php 4 years ago abstract-wc-payment-gateway.php 5 years ago abstract-wc-payment-token.php 5 years ago abstract-wc-privacy.php 5 years ago abstract-wc-product.php 4 years ago abstract-wc-session.php 5 years ago abstract-wc-settings-api.php 5 years ago abstract-wc-shipping-method.php 5 years ago abstract-wc-widget.php 4 years ago class-wc-background-process.php 5 years ago
abstract-wc-widget.php
409 lines
1 <?php
2 /**
3 * Abstract widget class
4 *
5 * @class WC_Widget
6 * @package WooCommerce\Abstracts
7 */
8
9 use Automattic\Jetpack\Constants;
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 /**
16 * WC_Widget
17 *
18 * @package WooCommerce\Abstracts
19 * @version 2.5.0
20 * @extends WP_Widget
21 */
22 abstract class WC_Widget extends WP_Widget {
23
24 /**
25 * CSS class.
26 *
27 * @var string
28 */
29 public $widget_cssclass;
30
31 /**
32 * Widget description.
33 *
34 * @var string
35 */
36 public $widget_description;
37
38 /**
39 * Widget ID.
40 *
41 * @var string
42 */
43 public $widget_id;
44
45 /**
46 * Widget name.
47 *
48 * @var string
49 */
50 public $widget_name;
51
52 /**
53 * Settings.
54 *
55 * @var array
56 */
57 public $settings;
58
59 /**
60 * Constructor.
61 */
62 public function __construct() {
63 $widget_ops = array(
64 'classname' => $this->widget_cssclass,
65 'description' => $this->widget_description,
66 'customize_selective_refresh' => true,
67 'show_instance_in_rest' => true,
68 );
69
70 parent::__construct( $this->widget_id, $this->widget_name, $widget_ops );
71
72 add_action( 'save_post', array( $this, 'flush_widget_cache' ) );
73 add_action( 'deleted_post', array( $this, 'flush_widget_cache' ) );
74 add_action( 'switch_theme', array( $this, 'flush_widget_cache' ) );
75 }
76
77 /**
78 * Get cached widget.
79 *
80 * @param array $args Arguments.
81 * @return bool true if the widget is cached otherwise false
82 */
83 public function get_cached_widget( $args ) {
84 // Don't get cache if widget_id doesn't exists.
85 if ( empty( $args['widget_id'] ) ) {
86 return false;
87 }
88
89 $cache = wp_cache_get( $this->get_widget_id_for_cache( $this->widget_id ), 'widget' );
90
91 if ( ! is_array( $cache ) ) {
92 $cache = array();
93 }
94
95 if ( isset( $cache[ $this->get_widget_id_for_cache( $args['widget_id'] ) ] ) ) {
96 echo $cache[ $this->get_widget_id_for_cache( $args['widget_id'] ) ]; // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped
97 return true;
98 }
99
100 return false;
101 }
102
103 /**
104 * Cache the widget.
105 *
106 * @param array $args Arguments.
107 * @param string $content Content.
108 * @return string the content that was cached
109 */
110 public function cache_widget( $args, $content ) {
111 // Don't set any cache if widget_id doesn't exist.
112 if ( empty( $args['widget_id'] ) ) {
113 return $content;
114 }
115
116 $cache = wp_cache_get( $this->get_widget_id_for_cache( $this->widget_id ), 'widget' );
117
118 if ( ! is_array( $cache ) ) {
119 $cache = array();
120 }
121
122 $cache[ $this->get_widget_id_for_cache( $args['widget_id'] ) ] = $content;
123
124 wp_cache_set( $this->get_widget_id_for_cache( $this->widget_id ), $cache, 'widget' );
125
126 return $content;
127 }
128
129 /**
130 * Flush the cache.
131 */
132 public function flush_widget_cache() {
133 foreach ( array( 'https', 'http' ) as $scheme ) {
134 wp_cache_delete( $this->get_widget_id_for_cache( $this->widget_id, $scheme ), 'widget' );
135 }
136 }
137
138 /**
139 * Get this widgets title.
140 *
141 * @param array $instance Array of instance options.
142 * @return string
143 */
144 protected function get_instance_title( $instance ) {
145 if ( isset( $instance['title'] ) ) {
146 return $instance['title'];
147 }
148
149 if ( isset( $this->settings, $this->settings['title'], $this->settings['title']['std'] ) ) {
150 return $this->settings['title']['std'];
151 }
152
153 return '';
154 }
155
156 /**
157 * Output the html at the start of a widget.
158 *
159 * @param array $args Arguments.
160 * @param array $instance Instance.
161 */
162 public function widget_start( $args, $instance ) {
163 echo $args['before_widget']; // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped
164
165 $title = apply_filters( 'widget_title', $this->get_instance_title( $instance ), $instance, $this->id_base );
166
167 if ( $title ) {
168 echo $args['before_title'] . $title . $args['after_title']; // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped
169 }
170 }
171
172 /**
173 * Output the html at the end of a widget.
174 *
175 * @param array $args Arguments.
176 */
177 public function widget_end( $args ) {
178 echo $args['after_widget']; // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped
179 }
180
181 /**
182 * Updates a particular instance of a widget.
183 *
184 * @see WP_Widget->update
185 * @param array $new_instance New instance.
186 * @param array $old_instance Old instance.
187 * @return array
188 */
189 public function update( $new_instance, $old_instance ) {
190
191 $instance = $old_instance;
192
193 if ( empty( $this->settings ) ) {
194 return $instance;
195 }
196
197 // Loop settings and get values to save.
198 foreach ( $this->settings as $key => $setting ) {
199 if ( ! isset( $setting['type'] ) ) {
200 continue;
201 }
202
203 // Format the value based on settings type.
204 switch ( $setting['type'] ) {
205 case 'number':
206 $instance[ $key ] = absint( $new_instance[ $key ] );
207
208 if ( isset( $setting['min'] ) && '' !== $setting['min'] ) {
209 $instance[ $key ] = max( $instance[ $key ], $setting['min'] );
210 }
211
212 if ( isset( $setting['max'] ) && '' !== $setting['max'] ) {
213 $instance[ $key ] = min( $instance[ $key ], $setting['max'] );
214 }
215 break;
216 case 'textarea':
217 $instance[ $key ] = wp_kses( trim( wp_unslash( $new_instance[ $key ] ) ), wp_kses_allowed_html( 'post' ) );
218 break;
219 case 'checkbox':
220 $instance[ $key ] = empty( $new_instance[ $key ] ) ? 0 : 1;
221 break;
222 default:
223 $instance[ $key ] = isset( $new_instance[ $key ] ) ? sanitize_text_field( $new_instance[ $key ] ) : $setting['std'];
224 break;
225 }
226
227 /**
228 * Sanitize the value of a setting.
229 */
230 $instance[ $key ] = apply_filters( 'woocommerce_widget_settings_sanitize_option', $instance[ $key ], $new_instance, $key, $setting );
231 }
232
233 $this->flush_widget_cache();
234
235 return $instance;
236 }
237
238 /**
239 * Outputs the settings update form.
240 *
241 * @see WP_Widget->form
242 *
243 * @param array $instance Instance.
244 */
245 public function form( $instance ) {
246
247 if ( empty( $this->settings ) ) {
248 return;
249 }
250
251 foreach ( $this->settings as $key => $setting ) {
252
253 $class = isset( $setting['class'] ) ? $setting['class'] : '';
254 $value = isset( $instance[ $key ] ) ? $instance[ $key ] : $setting['std'];
255
256 switch ( $setting['type'] ) {
257
258 case 'text':
259 ?>
260 <p>
261 <label for="<?php echo esc_attr( $this->get_field_id( $key ) ); ?>"><?php echo wp_kses_post( $setting['label'] ); ?></label><?php // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped ?>
262 <input class="widefat <?php echo esc_attr( $class ); ?>" id="<?php echo esc_attr( $this->get_field_id( $key ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( $key ) ); ?>" type="text" value="<?php echo esc_attr( $value ); ?>" />
263 </p>
264 <?php
265 break;
266
267 case 'number':
268 ?>
269 <p>
270 <label for="<?php echo esc_attr( $this->get_field_id( $key ) ); ?>"><?php echo $setting['label']; /* phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped */ ?></label>
271 <input class="widefat <?php echo esc_attr( $class ); ?>" id="<?php echo esc_attr( $this->get_field_id( $key ) ); ?>" name="<?php echo esc_attr( $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 ); ?>" />
272 </p>
273 <?php
274 break;
275
276 case 'select':
277 ?>
278 <p>
279 <label for="<?php echo esc_attr( $this->get_field_id( $key ) ); ?>"><?php echo $setting['label']; /* phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped */ ?></label>
280 <select class="widefat <?php echo esc_attr( $class ); ?>" id="<?php echo esc_attr( $this->get_field_id( $key ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( $key ) ); ?>">
281 <?php foreach ( $setting['options'] as $option_key => $option_value ) : ?>
282 <option value="<?php echo esc_attr( $option_key ); ?>" <?php selected( $option_key, $value ); ?>><?php echo esc_html( $option_value ); ?></option>
283 <?php endforeach; ?>
284 </select>
285 </p>
286 <?php
287 break;
288
289 case 'textarea':
290 ?>
291 <p>
292 <label for="<?php echo esc_attr( $this->get_field_id( $key ) ); ?>"><?php echo $setting['label']; /* phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped */ ?></label>
293 <textarea class="widefat <?php echo esc_attr( $class ); ?>" id="<?php echo esc_attr( $this->get_field_id( $key ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( $key ) ); ?>" cols="20" rows="3"><?php echo esc_textarea( $value ); ?></textarea>
294 <?php if ( isset( $setting['desc'] ) ) : ?>
295 <small><?php echo esc_html( $setting['desc'] ); ?></small>
296 <?php endif; ?>
297 </p>
298 <?php
299 break;
300
301 case 'checkbox':
302 ?>
303 <p>
304 <input class="checkbox <?php echo esc_attr( $class ); ?>" 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, 1 ); ?> />
305 <label for="<?php echo esc_attr( $this->get_field_id( $key ) ); ?>"><?php echo $setting['label']; /* phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped */ ?></label>
306 </p>
307 <?php
308 break;
309
310 // Default: run an action.
311 default:
312 do_action( 'woocommerce_widget_field_' . $setting['type'], $key, $value, $setting, $instance );
313 break;
314 }
315 }
316 }
317
318 /**
319 * Get current page URL with various filtering props supported by WC.
320 *
321 * @return string
322 * @since 3.3.0
323 */
324 protected function get_current_page_url() {
325 if ( Constants::is_defined( 'SHOP_IS_ON_FRONT' ) ) {
326 $link = home_url();
327 } elseif ( is_shop() ) {
328 $link = get_permalink( wc_get_page_id( 'shop' ) );
329 } elseif ( is_product_category() ) {
330 $link = get_term_link( get_query_var( 'product_cat' ), 'product_cat' );
331 } elseif ( is_product_tag() ) {
332 $link = get_term_link( get_query_var( 'product_tag' ), 'product_tag' );
333 } else {
334 $queried_object = get_queried_object();
335 $link = get_term_link( $queried_object->slug, $queried_object->taxonomy );
336 }
337
338 // Min/Max.
339 if ( isset( $_GET['min_price'] ) ) {
340 $link = add_query_arg( 'min_price', wc_clean( wp_unslash( $_GET['min_price'] ) ), $link );
341 }
342
343 if ( isset( $_GET['max_price'] ) ) {
344 $link = add_query_arg( 'max_price', wc_clean( wp_unslash( $_GET['max_price'] ) ), $link );
345 }
346
347 // Order by.
348 if ( isset( $_GET['orderby'] ) ) {
349 $link = add_query_arg( 'orderby', wc_clean( wp_unslash( $_GET['orderby'] ) ), $link );
350 }
351
352 /**
353 * Search Arg.
354 * To support quote characters, first they are decoded from &quot; entities, then URL encoded.
355 */
356 if ( get_search_query() ) {
357 $link = add_query_arg( 's', rawurlencode( htmlspecialchars_decode( get_search_query() ) ), $link );
358 }
359
360 // Post Type Arg.
361 if ( isset( $_GET['post_type'] ) ) {
362 $link = add_query_arg( 'post_type', wc_clean( wp_unslash( $_GET['post_type'] ) ), $link );
363
364 // Prevent post type and page id when pretty permalinks are disabled.
365 if ( is_shop() ) {
366 $link = remove_query_arg( 'page_id', $link );
367 }
368 }
369
370 // Min Rating Arg.
371 if ( isset( $_GET['rating_filter'] ) ) {
372 $link = add_query_arg( 'rating_filter', wc_clean( wp_unslash( $_GET['rating_filter'] ) ), $link );
373 }
374
375 // All current filters.
376 if ( $_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes() ) { // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure, WordPress.CodeAnalysis.AssignmentInCondition.Found
377 foreach ( $_chosen_attributes as $name => $data ) {
378 $filter_name = wc_attribute_taxonomy_slug( $name );
379 if ( ! empty( $data['terms'] ) ) {
380 $link = add_query_arg( 'filter_' . $filter_name, implode( ',', $data['terms'] ), $link );
381 }
382 if ( 'or' === $data['query_type'] ) {
383 $link = add_query_arg( 'query_type_' . $filter_name, 'or', $link );
384 }
385 }
386 }
387
388 return apply_filters( 'woocommerce_widget_get_current_page_url', $link, $this );
389 }
390
391 /**
392 * Get widget id plus scheme/protocol to prevent serving mixed content from (persistently) cached widgets.
393 *
394 * @since 3.4.0
395 * @param string $widget_id Id of the cached widget.
396 * @param string $scheme Scheme for the widget id.
397 * @return string Widget id including scheme/protocol.
398 */
399 protected function get_widget_id_for_cache( $widget_id, $scheme = '' ) {
400 if ( $scheme ) {
401 $widget_id_for_cache = $widget_id . '-' . $scheme;
402 } else {
403 $widget_id_for_cache = $widget_id . '-' . ( is_ssl() ? 'https' : 'http' );
404 }
405
406 return apply_filters( 'woocommerce_cached_widget_id', $widget_id_for_cache );
407 }
408 }
409