8 * Includes both internal WordPress routines and theme-use routines. |
8 * Includes both internal WordPress routines and theme-use routines. |
9 * |
9 * |
10 * This functionality was found in a plugin before the WordPress 2.2 release, which |
10 * This functionality was found in a plugin before the WordPress 2.2 release, which |
11 * included it in the core from that point on. |
11 * included it in the core from that point on. |
12 * |
12 * |
13 * @link https://codex.wordpress.org/Plugins/WordPress_Widgets WordPress Widgets |
13 * @link https://wordpress.org/support/article/wordpress-widgets/ |
14 * @link https://codex.wordpress.org/Plugins/WordPress_Widgets_Api Widgets API |
14 * @link https://developer.wordpress.org/themes/functionality/widgets/ |
15 * |
15 * |
16 * @package WordPress |
16 * @package WordPress |
17 * @subpackage Widgets |
17 * @subpackage Widgets |
18 * @since 2.2.0 |
18 * @since 2.2.0 |
19 */ |
19 */ |
20 |
20 |
21 // |
21 // |
22 // Global Variables |
22 // Global Variables. |
23 // |
23 // |
24 |
24 |
25 /** @ignore */ |
25 /** @ignore */ |
26 global $wp_registered_sidebars, $wp_registered_widgets, $wp_registered_widget_controls, $wp_registered_widget_updates; |
26 global $wp_registered_sidebars, $wp_registered_widgets, $wp_registered_widget_controls, $wp_registered_widget_updates; |
27 |
27 |
153 * @param int $number Optional. Number of sidebars to create. Default 1. |
153 * @param int $number Optional. Number of sidebars to create. Default 1. |
154 * @param array|string $args { |
154 * @param array|string $args { |
155 * Optional. Array or string of arguments for building a sidebar. |
155 * Optional. Array or string of arguments for building a sidebar. |
156 * |
156 * |
157 * @type string $id The base string of the unique identifier for each sidebar. If provided, and multiple |
157 * @type string $id The base string of the unique identifier for each sidebar. If provided, and multiple |
158 * sidebars are being defined, the id will have "-2" appended, and so on. |
158 * sidebars are being defined, the ID will have "-2" appended, and so on. |
159 * Default 'sidebar-' followed by the number the sidebar creation is currently at. |
159 * Default 'sidebar-' followed by the number the sidebar creation is currently at. |
160 * @type string $name The name or title for the sidebars displayed in the admin dashboard. If registering |
160 * @type string $name The name or title for the sidebars displayed in the admin dashboard. If registering |
161 * more than one sidebar, include '%d' in the string as a placeholder for the uniquely |
161 * more than one sidebar, include '%d' in the string as a placeholder for the uniquely |
162 * assigned number for each sidebar. |
162 * assigned number for each sidebar. |
163 * Default 'Sidebar' for the first sidebar, otherwise 'Sidebar %d'. |
163 * Default 'Sidebar' for the first sidebar, otherwise 'Sidebar %d'. |
173 |
173 |
174 for ( $i = 1; $i <= $number; $i++ ) { |
174 for ( $i = 1; $i <= $number; $i++ ) { |
175 $_args = $args; |
175 $_args = $args; |
176 |
176 |
177 if ( $number > 1 ) { |
177 if ( $number > 1 ) { |
178 $_args['name'] = isset( $args['name'] ) ? sprintf( $args['name'], $i ) : sprintf( __( 'Sidebar %d' ), $i ); |
178 if ( isset( $args['name'] ) ) { |
|
179 $_args['name'] = sprintf( $args['name'], $i ); |
|
180 } else { |
|
181 /* translators: %d: Sidebar number. */ |
|
182 $_args['name'] = sprintf( __( 'Sidebar %d' ), $i ); |
|
183 } |
179 } else { |
184 } else { |
180 $_args['name'] = isset( $args['name'] ) ? $args['name'] : __( 'Sidebar' ); |
185 $_args['name'] = isset( $args['name'] ) ? $args['name'] : __( 'Sidebar' ); |
181 } |
186 } |
182 |
187 |
183 // Custom specified ID's are suffixed if they exist already. |
188 // Custom specified ID's are suffixed if they exist already. |
184 // Automatically generated sidebar names need to be suffixed regardless starting at -0 |
189 // Automatically generated sidebar names need to be suffixed regardless starting at -0. |
185 if ( isset( $args['id'] ) ) { |
190 if ( isset( $args['id'] ) ) { |
186 $_args['id'] = $args['id']; |
191 $_args['id'] = $args['id']; |
187 $n = 2; // Start at -2 for conflicting custom ID's |
192 $n = 2; // Start at -2 for conflicting custom IDs. |
188 while ( is_registered_sidebar( $_args['id'] ) ) { |
193 while ( is_registered_sidebar( $_args['id'] ) ) { |
189 $_args['id'] = $args['id'] . '-' . $n++; |
194 $_args['id'] = $args['id'] . '-' . $n++; |
190 } |
195 } |
191 } else { |
196 } else { |
192 $n = count( $wp_registered_sidebars ); |
197 $n = count( $wp_registered_sidebars ); |
213 * If theme support for 'widgets' has not yet been added when this function is |
218 * If theme support for 'widgets' has not yet been added when this function is |
214 * called, it will be automatically enabled through the use of add_theme_support() |
219 * called, it will be automatically enabled through the use of add_theme_support() |
215 * |
220 * |
216 * @since 2.2.0 |
221 * @since 2.2.0 |
217 * |
222 * |
218 * @global array $wp_registered_sidebars Stores the new sidebar in this array by sidebar ID. |
223 * @global array $wp_registered_sidebars Registered sidebars. |
219 * |
224 * |
220 * @param array|string $args { |
225 * @param array|string $args { |
221 * Optional. Array or string of arguments for the sidebar being registered. |
226 * Optional. Array or string of arguments for the sidebar being registered. |
222 * |
227 * |
223 * @type string $name The name or title of the sidebar displayed in the Widgets |
228 * @type string $name The name or title of the sidebar displayed in the Widgets |
245 $i = count( $wp_registered_sidebars ) + 1; |
250 $i = count( $wp_registered_sidebars ) + 1; |
246 |
251 |
247 $id_is_empty = empty( $args['id'] ); |
252 $id_is_empty = empty( $args['id'] ); |
248 |
253 |
249 $defaults = array( |
254 $defaults = array( |
|
255 /* translators: %d: Sidebar number. */ |
250 'name' => sprintf( __( 'Sidebar %d' ), $i ), |
256 'name' => sprintf( __( 'Sidebar %d' ), $i ), |
251 'id' => "sidebar-$i", |
257 'id' => "sidebar-$i", |
252 'description' => '', |
258 'description' => '', |
253 'class' => '', |
259 'class' => '', |
254 'before_widget' => '<li id="%1$s" class="widget %2$s">', |
260 'before_widget' => '<li id="%1$s" class="widget %2$s">', |
255 'after_widget' => "</li>\n", |
261 'after_widget' => "</li>\n", |
256 'before_title' => '<h2 class="widgettitle">', |
262 'before_title' => '<h2 class="widgettitle">', |
257 'after_title' => "</h2>\n", |
263 'after_title' => "</h2>\n", |
258 ); |
264 ); |
259 |
265 |
260 $sidebar = wp_parse_args( $args, $defaults ); |
266 /** |
|
267 * Filters the sidebar default arguments. |
|
268 * |
|
269 * @since 5.3.0 |
|
270 * |
|
271 * @see register_sidebar() |
|
272 * |
|
273 * @param array $defaults The default sidebar arguments. |
|
274 */ |
|
275 $sidebar = wp_parse_args( $args, apply_filters( 'register_sidebar_defaults', $defaults ) ); |
261 |
276 |
262 if ( $id_is_empty ) { |
277 if ( $id_is_empty ) { |
263 /* translators: 1: the id argument, 2: sidebar name, 3: recommended id value */ |
278 _doing_it_wrong( |
264 _doing_it_wrong( __FUNCTION__, sprintf( __( 'No %1$s was set in the arguments array for the "%2$s" sidebar. Defaulting to "%3$s". Manually set the %1$s to "%3$s" to silence this notice and keep existing sidebar content.' ), '<code>id</code>', $sidebar['name'], $sidebar['id'] ), '4.2.0' ); |
279 __FUNCTION__, |
|
280 sprintf( |
|
281 /* translators: 1: The 'id' argument, 2: Sidebar name, 3: Recommended 'id' value. */ |
|
282 __( 'No %1$s was set in the arguments array for the "%2$s" sidebar. Defaulting to "%3$s". Manually set the %1$s to "%3$s" to silence this notice and keep existing sidebar content.' ), |
|
283 '<code>id</code>', |
|
284 $sidebar['name'], |
|
285 $sidebar['id'] |
|
286 ), |
|
287 '4.2.0' |
|
288 ); |
265 } |
289 } |
266 |
290 |
267 $wp_registered_sidebars[ $sidebar['id'] ] = $sidebar; |
291 $wp_registered_sidebars[ $sidebar['id'] ] = $sidebar; |
268 |
292 |
269 add_theme_support( 'widgets' ); |
293 add_theme_support( 'widgets' ); |
318 * |
342 * |
319 * The function can also be used to un-register widgets when `$output_callback` |
343 * The function can also be used to un-register widgets when `$output_callback` |
320 * parameter is an empty string. |
344 * parameter is an empty string. |
321 * |
345 * |
322 * @since 2.2.0 |
346 * @since 2.2.0 |
|
347 * @since 5.3.0 Formalized the existing and already documented `...$params` parameter |
|
348 * by adding it to the function signature. |
323 * |
349 * |
324 * @global array $wp_registered_widgets Uses stored registered widgets. |
350 * @global array $wp_registered_widgets Uses stored registered widgets. |
325 * @global array $wp_registered_widget_controls Stores the registered widget controls (options). |
351 * @global array $wp_registered_widget_controls Stores the registered widget controls (options). |
326 * @global array $wp_registered_widget_updates |
352 * @global array $wp_registered_widget_updates |
327 * @global array $_wp_deprecated_widgets_callbacks |
353 * @global array $_wp_deprecated_widgets_callbacks |
335 * @type string $classname Class name for the widget's HTML container. Default is a shortened |
361 * @type string $classname Class name for the widget's HTML container. Default is a shortened |
336 * version of the output callback name. |
362 * version of the output callback name. |
337 * @type string $description Widget description for display in the widget administration |
363 * @type string $description Widget description for display in the widget administration |
338 * panel and/or theme. |
364 * panel and/or theme. |
339 * } |
365 * } |
340 */ |
366 * @param mixed ...$params Optional additional parameters to pass to the callback function when it's called. |
341 function wp_register_sidebar_widget( $id, $name, $output_callback, $options = array() ) { |
367 */ |
|
368 function wp_register_sidebar_widget( $id, $name, $output_callback, $options = array(), ...$params ) { |
342 global $wp_registered_widgets, $wp_registered_widget_controls, $wp_registered_widget_updates, $_wp_deprecated_widgets_callbacks; |
369 global $wp_registered_widgets, $wp_registered_widget_controls, $wp_registered_widget_updates, $_wp_deprecated_widgets_callbacks; |
343 |
370 |
344 $id = strtolower( $id ); |
371 $id = strtolower( $id ); |
345 |
372 |
346 if ( empty( $output_callback ) ) { |
373 if ( empty( $output_callback ) ) { |
359 $options = wp_parse_args( $options, $defaults ); |
386 $options = wp_parse_args( $options, $defaults ); |
360 $widget = array( |
387 $widget = array( |
361 'name' => $name, |
388 'name' => $name, |
362 'id' => $id, |
389 'id' => $id, |
363 'callback' => $output_callback, |
390 'callback' => $output_callback, |
364 'params' => array_slice( func_get_args(), 4 ), |
391 'params' => $params, |
365 ); |
392 ); |
366 $widget = array_merge( $widget, $options ); |
393 $widget = array_merge( $widget, $options ); |
367 |
394 |
368 if ( is_callable( $output_callback ) && ( ! isset( $wp_registered_widgets[ $id ] ) || did_action( 'widgets_init' ) ) ) { |
395 if ( is_callable( $output_callback ) && ( ! isset( $wp_registered_widgets[ $id ] ) || did_action( 'widgets_init' ) ) ) { |
369 |
396 |
454 |
481 |
455 /** |
482 /** |
456 * Registers widget control callback for customizing options. |
483 * Registers widget control callback for customizing options. |
457 * |
484 * |
458 * @since 2.2.0 |
485 * @since 2.2.0 |
459 * |
486 * @since 5.3.0 Formalized the existing and already documented `...$params` parameter |
460 * @todo `$params` parameter? |
487 * by adding it to the function signature. |
461 * |
488 * |
462 * @global array $wp_registered_widget_controls |
489 * @global array $wp_registered_widget_controls |
463 * @global array $wp_registered_widget_updates |
490 * @global array $wp_registered_widget_updates |
464 * @global array $wp_registered_widgets |
491 * @global array $wp_registered_widgets |
465 * @global array $_wp_deprecated_widgets_callbacks |
492 * @global array $_wp_deprecated_widgets_callbacks |
466 * |
493 * |
467 * @param int|string $id Sidebar ID. |
494 * @param int|string $id Sidebar ID. |
468 * @param string $name Sidebar display name. |
495 * @param string $name Sidebar display name. |
469 * @param callable $control_callback Run when sidebar is displayed. |
496 * @param callable $control_callback Run when sidebar is displayed. |
470 * @param array $options { |
497 * @param array $options { |
471 * Optional. Array or string of control options. Default empty array. |
498 * Optional. Array or string of control options. Default empty array. |
472 * |
499 * |
473 * @type int $height Never used. Default 200. |
500 * @type int $height Never used. Default 200. |
474 * @type int $width Width of the fully expanded control form (but try hard to use the default width). |
501 * @type int $width Width of the fully expanded control form (but try hard to use the default width). |
475 * Default 250. |
502 * Default 250. |
476 * @type int|string $id_base Required for multi-widgets, i.e widgets that allow multiple instances such as the |
503 * @type int|string $id_base Required for multi-widgets, i.e widgets that allow multiple instances such as the |
477 * text widget. The widget id will end up looking like `{$id_base}-{$unique_number}`. |
504 * text widget. The widget id will end up looking like `{$id_base}-{$unique_number}`. |
478 * } |
505 * } |
479 */ |
506 * @param mixed ...$params Optional additional parameters to pass to the callback function when it's called. |
480 function wp_register_widget_control( $id, $name, $control_callback, $options = array() ) { |
507 */ |
|
508 function wp_register_widget_control( $id, $name, $control_callback, $options = array(), ...$params ) { |
481 global $wp_registered_widget_controls, $wp_registered_widget_updates, $wp_registered_widgets, $_wp_deprecated_widgets_callbacks; |
509 global $wp_registered_widget_controls, $wp_registered_widget_updates, $wp_registered_widgets, $_wp_deprecated_widgets_callbacks; |
482 |
510 |
483 $id = strtolower( $id ); |
511 $id = strtolower( $id ); |
484 $id_base = _get_widget_id_base( $id ); |
512 $id_base = _get_widget_id_base( $id ); |
485 |
513 |
499 } |
527 } |
500 |
528 |
501 $defaults = array( |
529 $defaults = array( |
502 'width' => 250, |
530 'width' => 250, |
503 'height' => 200, |
531 'height' => 200, |
504 ); // height is never used |
532 ); // Height is never used. |
505 $options = wp_parse_args( $options, $defaults ); |
533 $options = wp_parse_args( $options, $defaults ); |
506 $options['width'] = (int) $options['width']; |
534 $options['width'] = (int) $options['width']; |
507 $options['height'] = (int) $options['height']; |
535 $options['height'] = (int) $options['height']; |
508 |
536 |
509 $widget = array( |
537 $widget = array( |
510 'name' => $name, |
538 'name' => $name, |
511 'id' => $id, |
539 'id' => $id, |
512 'callback' => $control_callback, |
540 'callback' => $control_callback, |
513 'params' => array_slice( func_get_args(), 4 ), |
541 'params' => $params, |
514 ); |
542 ); |
515 $widget = array_merge( $widget, $options ); |
543 $widget = array_merge( $widget, $options ); |
516 |
544 |
517 $wp_registered_widget_controls[ $id ] = $widget; |
545 $wp_registered_widget_controls[ $id ] = $widget; |
518 |
546 |
530 |
558 |
531 /** |
559 /** |
532 * Registers the update callback for a widget. |
560 * Registers the update callback for a widget. |
533 * |
561 * |
534 * @since 2.8.0 |
562 * @since 2.8.0 |
|
563 * @since 5.3.0 Formalized the existing and already documented `...$params` parameter |
|
564 * by adding it to the function signature. |
535 * |
565 * |
536 * @global array $wp_registered_widget_updates |
566 * @global array $wp_registered_widget_updates |
537 * |
567 * |
538 * @param string $id_base The base ID of a widget created by extending WP_Widget. |
568 * @param string $id_base The base ID of a widget created by extending WP_Widget. |
539 * @param callable $update_callback Update callback method for the widget. |
569 * @param callable $update_callback Update callback method for the widget. |
540 * @param array $options Optional. Widget control options. See wp_register_widget_control(). |
570 * @param array $options Optional. Widget control options. See wp_register_widget_control(). |
541 * Default empty array. |
571 * Default empty array. |
542 */ |
572 * @param mixed ...$params Optional additional parameters to pass to the callback function when it's called. |
543 function _register_widget_update_callback( $id_base, $update_callback, $options = array() ) { |
573 */ |
|
574 function _register_widget_update_callback( $id_base, $update_callback, $options = array(), ...$params ) { |
544 global $wp_registered_widget_updates; |
575 global $wp_registered_widget_updates; |
545 |
576 |
546 if ( isset( $wp_registered_widget_updates[ $id_base ] ) ) { |
577 if ( isset( $wp_registered_widget_updates[ $id_base ] ) ) { |
547 if ( empty( $update_callback ) ) { |
578 if ( empty( $update_callback ) ) { |
548 unset( $wp_registered_widget_updates[ $id_base ] ); |
579 unset( $wp_registered_widget_updates[ $id_base ] ); |
550 return; |
581 return; |
551 } |
582 } |
552 |
583 |
553 $widget = array( |
584 $widget = array( |
554 'callback' => $update_callback, |
585 'callback' => $update_callback, |
555 'params' => array_slice( func_get_args(), 3 ), |
586 'params' => $params, |
556 ); |
587 ); |
557 |
588 |
558 $widget = array_merge( $widget, $options ); |
589 $widget = array_merge( $widget, $options ); |
559 $wp_registered_widget_updates[ $id_base ] = $widget; |
590 $wp_registered_widget_updates[ $id_base ] = $widget; |
560 } |
591 } |
561 |
592 |
562 /** |
593 /** |
563 * Registers the form callback for a widget. |
594 * Registers the form callback for a widget. |
564 * |
595 * |
565 * @since 2.8.0 |
596 * @since 2.8.0 |
|
597 * @since 5.3.0 Formalized the existing and already documented `...$params` parameter |
|
598 * by adding it to the function signature. |
566 * |
599 * |
567 * @global array $wp_registered_widget_controls |
600 * @global array $wp_registered_widget_controls |
568 * |
601 * |
569 * @param int|string $id Widget ID. |
602 * @param int|string $id Widget ID. |
570 * @param string $name Name attribute for the widget. |
603 * @param string $name Name attribute for the widget. |
571 * @param callable $form_callback Form callback. |
604 * @param callable $form_callback Form callback. |
572 * @param array $options Optional. Widget control options. See wp_register_widget_control(). |
605 * @param array $options Optional. Widget control options. See wp_register_widget_control(). |
573 * Default empty array. |
606 * Default empty array. |
574 */ |
607 * @param mixed ...$params Optional additional parameters to pass to the callback function when it's called. |
575 function _register_widget_form_callback( $id, $name, $form_callback, $options = array() ) { |
608 */ |
|
609 |
|
610 function _register_widget_form_callback( $id, $name, $form_callback, $options = array(), ...$params ) { |
576 global $wp_registered_widget_controls; |
611 global $wp_registered_widget_controls; |
577 |
612 |
578 $id = strtolower( $id ); |
613 $id = strtolower( $id ); |
579 |
614 |
580 if ( empty( $form_callback ) ) { |
615 if ( empty( $form_callback ) ) { |
618 |
653 |
619 /** |
654 /** |
620 * Display dynamic sidebar. |
655 * Display dynamic sidebar. |
621 * |
656 * |
622 * By default this displays the default sidebar or 'sidebar-1'. If your theme specifies the 'id' or |
657 * By default this displays the default sidebar or 'sidebar-1'. If your theme specifies the 'id' or |
623 * 'name' parameter for its registered sidebars you can pass an id or name as the $index parameter. |
658 * 'name' parameter for its registered sidebars you can pass an ID or name as the $index parameter. |
624 * Otherwise, you can pass in a numerical index to display the sidebar at that index. |
659 * Otherwise, you can pass in a numerical index to display the sidebar at that index. |
625 * |
660 * |
626 * @since 2.2.0 |
661 * @since 2.2.0 |
627 * |
662 * |
628 * @global array $wp_registered_sidebars Registered sidebars. |
663 * @global array $wp_registered_sidebars Registered sidebars. |
629 * @global array $wp_registered_widgets |
664 * @global array $wp_registered_widgets Registered widgets. |
630 * |
665 * |
631 * @param int|string $index Optional, default is 1. Index, name or ID of dynamic sidebar. |
666 * @param int|string $index Optional. Index, name or ID of dynamic sidebar. Default 1. |
632 * @return bool True, if widget sidebar was found and called. False if not found or not called. |
667 * @return bool True, if widget sidebar was found and called. False if not found or not called. |
633 */ |
668 */ |
634 function dynamic_sidebar( $index = 1 ) { |
669 function dynamic_sidebar( $index = 1 ) { |
635 global $wp_registered_sidebars, $wp_registered_widgets; |
670 global $wp_registered_sidebars, $wp_registered_widgets; |
636 |
671 |
637 if ( is_int( $index ) ) { |
672 if ( is_int( $index ) ) { |
638 $index = "sidebar-$index"; |
673 $index = "sidebar-$index"; |
639 } else { |
674 } else { |
640 $index = sanitize_title( $index ); |
675 $index = sanitize_title( $index ); |
641 foreach ( (array) $wp_registered_sidebars as $key => $value ) { |
676 foreach ( (array) $wp_registered_sidebars as $key => $value ) { |
642 if ( sanitize_title( $value['name'] ) == $index ) { |
677 if ( sanitize_title( $value['name'] ) === $index ) { |
643 $index = $key; |
678 $index = $key; |
644 break; |
679 break; |
645 } |
680 } |
646 } |
681 } |
647 } |
682 } |
689 ), |
724 ), |
690 ), |
725 ), |
691 (array) $wp_registered_widgets[ $id ]['params'] |
726 (array) $wp_registered_widgets[ $id ]['params'] |
692 ); |
727 ); |
693 |
728 |
694 // Substitute HTML id and class attributes into before_widget |
729 // Substitute HTML `id` and `class` attributes into `before_widget`. |
695 $classname_ = ''; |
730 $classname_ = ''; |
696 foreach ( (array) $wp_registered_widgets[ $id ]['classname'] as $cn ) { |
731 foreach ( (array) $wp_registered_widgets[ $id ]['classname'] as $cn ) { |
697 if ( is_string( $cn ) ) { |
732 if ( is_string( $cn ) ) { |
698 $classname_ .= '_' . $cn; |
733 $classname_ .= '_' . $cn; |
699 } elseif ( is_object( $cn ) ) { |
734 } elseif ( is_object( $cn ) ) { |
750 * @since 3.0.0 |
785 * @since 3.0.0 |
751 * |
786 * |
752 * @param array $widget_id { |
787 * @param array $widget_id { |
753 * An associative array of widget arguments. |
788 * An associative array of widget arguments. |
754 * |
789 * |
755 * @type string $name Name of the widget. |
790 * @type string $name Name of the widget. |
756 * @type string $id Widget ID. |
791 * @type string $id Widget ID. |
757 * @type array|callable $callback When the hook is fired on the front end, $callback is an array |
792 * @type callable $callback When the hook is fired on the front end, $callback is an array |
758 * containing the widget object. Fired on the back end, $callback |
793 * containing the widget object. Fired on the back end, $callback |
759 * is 'wp_widget_control', see $_callback. |
794 * is 'wp_widget_control', see $_callback. |
760 * @type array $params An associative array of multi-widget arguments. |
795 * @type array $params An associative array of multi-widget arguments. |
761 * @type string $classname CSS class applied to the widget container. |
796 * @type string $classname CSS class applied to the widget container. |
762 * @type string $description The widget description. |
797 * @type string $description The widget description. |
763 * @type array $_callback When the hook is fired on the back end, $_callback is populated |
798 * @type array $_callback When the hook is fired on the back end, $_callback is populated |
764 * with an array containing the widget object, see $callback. |
799 * with an array containing the widget object, see $callback. |
765 * } |
800 * } |
766 */ |
801 */ |
767 do_action( 'dynamic_sidebar', $wp_registered_widgets[ $id ] ); |
802 do_action( 'dynamic_sidebar', $wp_registered_widgets[ $id ] ); |
768 |
803 |
769 if ( is_callable( $callback ) ) { |
804 if ( is_callable( $callback ) ) { |
820 * |
855 * |
821 * @since 2.2.0 |
856 * @since 2.2.0 |
822 * |
857 * |
823 * @global array $wp_registered_widgets |
858 * @global array $wp_registered_widgets |
824 * |
859 * |
825 * @param string|false $callback Optional, Widget callback to check. Default false. |
860 * @param callable|false $callback Optional, Widget callback to check. Default false. |
826 * @param int|false $widget_id Optional. Widget ID. Optional, but needed for checking. Default false. |
861 * @param int|false $widget_id Optional. Widget ID. Optional, but needed for checking. Default false. |
827 * @param string|false $id_base Optional. The base ID of a widget created by extending WP_Widget. Default false. |
862 * @param string|false $id_base Optional. The base ID of a widget created by extending WP_Widget. Default false. |
828 * @param bool $skip_inactive Optional. Whether to check in 'wp_inactive_widgets'. Default true. |
863 * @param bool $skip_inactive Optional. Whether to check in 'wp_inactive_widgets'. Default true. |
829 * @return string|false False if widget is not active or id of sidebar in which the widget is active. |
864 * @return string|false False if widget is not active or id of sidebar in which the widget is active. |
830 */ |
865 */ |
831 function is_active_widget( $callback = false, $widget_id = false, $id_base = false, $skip_inactive = true ) { |
866 function is_active_widget( $callback = false, $widget_id = false, $id_base = false, $skip_inactive = true ) { |
832 global $wp_registered_widgets; |
867 global $wp_registered_widgets; |
833 |
868 |
860 * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
895 * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
861 * Conditional Tags} article in the Theme Developer Handbook. |
896 * Conditional Tags} article in the Theme Developer Handbook. |
862 * |
897 * |
863 * @since 2.2.0 |
898 * @since 2.2.0 |
864 * |
899 * |
865 * @global array $wp_registered_widgets |
900 * @global array $wp_registered_widgets Registered widgets. |
866 * @global array $wp_registered_sidebars Registered sidebars. |
901 * @global array $wp_registered_sidebars Registered sidebars. |
867 * |
902 * |
868 * @return bool True, if using widgets. False, if not using widgets. |
903 * @return bool True if using widgets, false otherwise. |
869 */ |
904 */ |
870 function is_dynamic_sidebar() { |
905 function is_dynamic_sidebar() { |
871 global $wp_registered_widgets, $wp_registered_sidebars; |
906 global $wp_registered_widgets, $wp_registered_sidebars; |
|
907 |
872 $sidebars_widgets = get_option( 'sidebars_widgets' ); |
908 $sidebars_widgets = get_option( 'sidebars_widgets' ); |
|
909 |
873 foreach ( (array) $wp_registered_sidebars as $index => $sidebar ) { |
910 foreach ( (array) $wp_registered_sidebars as $index => $sidebar ) { |
874 if ( ! empty( $sidebars_widgets[ $index ] ) ) { |
911 if ( ! empty( $sidebars_widgets[ $index ] ) ) { |
875 foreach ( (array) $sidebars_widgets[ $index ] as $widget ) { |
912 foreach ( (array) $sidebars_widgets[ $index ] as $widget ) { |
876 if ( array_key_exists( $widget, $wp_registered_widgets ) ) { |
913 if ( array_key_exists( $widget, $wp_registered_widgets ) ) { |
877 return true; |
914 return true; |
878 } |
915 } |
879 } |
916 } |
880 } |
917 } |
881 } |
918 } |
|
919 |
882 return false; |
920 return false; |
883 } |
921 } |
884 |
922 |
885 /** |
923 /** |
886 * Determines whether a sidebar is in use. |
924 * Determines whether a sidebar contains widgets. |
887 * |
925 * |
888 * For more information on this and similar theme functions, check out |
926 * For more information on this and similar theme functions, check out |
889 * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
927 * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
890 * Conditional Tags} article in the Theme Developer Handbook. |
928 * Conditional Tags} article in the Theme Developer Handbook. |
891 * |
929 * |
892 * @since 2.8.0 |
930 * @since 2.8.0 |
893 * |
931 * |
894 * @param string|int $index Sidebar name, id or number to check. |
932 * @param string|int $index Sidebar name, id or number to check. |
895 * @return bool true if the sidebar is in use, false otherwise. |
933 * @return bool True if the sidebar has widgets, false otherwise. |
896 */ |
934 */ |
897 function is_active_sidebar( $index ) { |
935 function is_active_sidebar( $index ) { |
898 $index = ( is_int( $index ) ) ? "sidebar-$index" : sanitize_title( $index ); |
936 $index = ( is_int( $index ) ) ? "sidebar-$index" : sanitize_title( $index ); |
899 $sidebars_widgets = wp_get_sidebars_widgets(); |
937 $sidebars_widgets = wp_get_sidebars_widgets(); |
900 $is_active_sidebar = ! empty( $sidebars_widgets[ $index ] ); |
938 $is_active_sidebar = ! empty( $sidebars_widgets[ $index ] ); |
929 * |
967 * |
930 * @param bool $deprecated Not used (argument deprecated). |
968 * @param bool $deprecated Not used (argument deprecated). |
931 * @return array Upgraded list of widgets to version 3 array format when called from the admin. |
969 * @return array Upgraded list of widgets to version 3 array format when called from the admin. |
932 */ |
970 */ |
933 function wp_get_sidebars_widgets( $deprecated = true ) { |
971 function wp_get_sidebars_widgets( $deprecated = true ) { |
934 if ( $deprecated !== true ) { |
972 if ( true !== $deprecated ) { |
935 _deprecated_argument( __FUNCTION__, '2.8.1' ); |
973 _deprecated_argument( __FUNCTION__, '2.8.1' ); |
936 } |
974 } |
937 |
975 |
938 global $_wp_sidebars_widgets, $sidebars_widgets; |
976 global $_wp_sidebars_widgets, $sidebars_widgets; |
939 |
977 |
1006 |
1044 |
1007 return $defaults; |
1045 return $defaults; |
1008 } |
1046 } |
1009 |
1047 |
1010 /** |
1048 /** |
1011 * Convert the widget settings from single to multi-widget format. |
1049 * Converts the widget settings from single to multi-widget format. |
1012 * |
1050 * |
1013 * @since 2.8.0 |
1051 * @since 2.8.0 |
1014 * |
1052 * |
1015 * @global array $_wp_sidebars_widgets |
1053 * @global array $_wp_sidebars_widgets |
1016 * |
1054 * |
1017 * @param string $base_name |
1055 * @param string $base_name Root ID for all widgets of this type. |
1018 * @param string $option_name |
1056 * @param string $option_name Option name for this widget type. |
1019 * @param array $settings |
1057 * @param array $settings The array of widget instance settings. |
1020 * @return array |
1058 * @return array The array of widget settings converted to multi-widget format. |
1021 */ |
1059 */ |
1022 function wp_convert_widget_settings( $base_name, $option_name, $settings ) { |
1060 function wp_convert_widget_settings( $base_name, $option_name, $settings ) { |
1023 // This test may need expanding. |
1061 // This test may need expanding. |
1024 $single = $changed = false; |
1062 $single = false; |
|
1063 $changed = false; |
|
1064 |
1025 if ( empty( $settings ) ) { |
1065 if ( empty( $settings ) ) { |
1026 $single = true; |
1066 $single = true; |
1027 } else { |
1067 } else { |
1028 foreach ( array_keys( $settings ) as $number ) { |
1068 foreach ( array_keys( $settings ) as $number ) { |
1029 if ( 'number' == $number ) { |
1069 if ( 'number' === $number ) { |
1030 continue; |
1070 continue; |
1031 } |
1071 } |
1032 if ( ! is_numeric( $number ) ) { |
1072 if ( ! is_numeric( $number ) ) { |
1033 $single = true; |
1073 $single = true; |
1034 break; |
1074 break; |
1037 } |
1077 } |
1038 |
1078 |
1039 if ( $single ) { |
1079 if ( $single ) { |
1040 $settings = array( 2 => $settings ); |
1080 $settings = array( 2 => $settings ); |
1041 |
1081 |
1042 // If loading from the front page, update sidebar in memory but don't save to options |
1082 // If loading from the front page, update sidebar in memory but don't save to options. |
1043 if ( is_admin() ) { |
1083 if ( is_admin() ) { |
1044 $sidebars_widgets = get_option( 'sidebars_widgets' ); |
1084 $sidebars_widgets = get_option( 'sidebars_widgets' ); |
1045 } else { |
1085 } else { |
1046 if ( empty( $GLOBALS['_wp_sidebars_widgets'] ) ) { |
1086 if ( empty( $GLOBALS['_wp_sidebars_widgets'] ) ) { |
1047 $GLOBALS['_wp_sidebars_widgets'] = get_option( 'sidebars_widgets', array() ); |
1087 $GLOBALS['_wp_sidebars_widgets'] = get_option( 'sidebars_widgets', array() ); |
1098 */ |
1138 */ |
1099 function the_widget( $widget, $instance = array(), $args = array() ) { |
1139 function the_widget( $widget, $instance = array(), $args = array() ) { |
1100 global $wp_widget_factory; |
1140 global $wp_widget_factory; |
1101 |
1141 |
1102 if ( ! isset( $wp_widget_factory->widgets[ $widget ] ) ) { |
1142 if ( ! isset( $wp_widget_factory->widgets[ $widget ] ) ) { |
1103 /* translators: %s: register_widget() */ |
1143 _doing_it_wrong( |
1104 _doing_it_wrong( __FUNCTION__, sprintf( __( 'Widgets need to be registered using %s, before they can be displayed.' ), '<code>register_widget()</code>' ), '4.9.0' ); |
1144 __FUNCTION__, |
|
1145 sprintf( |
|
1146 /* translators: %s: register_widget() */ |
|
1147 __( 'Widgets need to be registered using %s, before they can be displayed.' ), |
|
1148 '<code>register_widget()</code>' |
|
1149 ), |
|
1150 '4.9.0' |
|
1151 ); |
1105 return; |
1152 return; |
1106 } |
1153 } |
1107 |
1154 |
1108 $widget_obj = $wp_widget_factory->widgets[ $widget ]; |
1155 $widget_obj = $wp_widget_factory->widgets[ $widget ]; |
1109 if ( ! ( $widget_obj instanceof WP_Widget ) ) { |
1156 if ( ! ( $widget_obj instanceof WP_Widget ) ) { |
1119 $args = wp_parse_args( $args, $default_args ); |
1166 $args = wp_parse_args( $args, $default_args ); |
1120 $args['before_widget'] = sprintf( $args['before_widget'], $widget_obj->widget_options['classname'] ); |
1167 $args['before_widget'] = sprintf( $args['before_widget'], $widget_obj->widget_options['classname'] ); |
1121 |
1168 |
1122 $instance = wp_parse_args( $instance ); |
1169 $instance = wp_parse_args( $instance ); |
1123 |
1170 |
|
1171 /** This filter is documented in wp-includes/class-wp-widget.php */ |
|
1172 $instance = apply_filters( 'widget_display_callback', $instance, $widget_obj, $args ); |
|
1173 |
|
1174 if ( false === $instance ) { |
|
1175 return; |
|
1176 } |
|
1177 |
1124 /** |
1178 /** |
1125 * Fires before rendering the requested widget. |
1179 * Fires before rendering the requested widget. |
1126 * |
1180 * |
1127 * @since 3.0.0 |
1181 * @since 3.0.0 |
1128 * |
1182 * |
1171 * |
1225 * |
1172 * @since 2.8.0 |
1226 * @since 2.8.0 |
1173 * |
1227 * |
1174 * @global array $wp_registered_sidebars Registered sidebars. |
1228 * @global array $wp_registered_sidebars Registered sidebars. |
1175 * @global array $sidebars_widgets |
1229 * @global array $sidebars_widgets |
1176 * @global array $wp_registered_widgets |
1230 * @global array $wp_registered_widgets Registered widgets. |
1177 * |
1231 * |
1178 * @param string|bool $theme_changed Whether the theme was changed as a boolean. A value |
1232 * @param string|bool $theme_changed Whether the theme was changed as a boolean. A value |
1179 * of 'customize' defers updates for the Customizer. |
1233 * of 'customize' defers updates for the Customizer. |
1180 * @return array Updated sidebars widgets. |
1234 * @return array Updated sidebars widgets. |
1181 */ |
1235 */ |
1324 unset( $existing_sidebars_widgets[ $sidebar ] ); |
1378 unset( $existing_sidebars_widgets[ $sidebar ] ); |
1325 |
1379 |
1326 // Go back and check the next new sidebar. |
1380 // Go back and check the next new sidebar. |
1327 continue 3; |
1381 continue 3; |
1328 } |
1382 } |
1329 } // endforeach ( $slug_group as $slug ) |
1383 } // End foreach ( $slug_group as $slug ). |
1330 } // endforeach ( $existing_sidebars_widgets as $sidebar => $widgets ) |
1384 } // End foreach ( $existing_sidebars_widgets as $sidebar => $widgets ). |
1331 } // endforeach foreach ( $wp_registered_sidebars as $new_sidebar => $args ) |
1385 } // End foreach ( $wp_registered_sidebars as $new_sidebar => $args ). |
1332 } // endforeach ( $slug_group as $slug ) |
1386 } // End foreach ( $slug_group as $slug ). |
1333 } // endforeach ( $common_slug_groups as $slug_group ) |
1387 } // End foreach ( $common_slug_groups as $slug_group ). |
1334 } |
1388 } |
1335 |
1389 |
1336 // Move any left over widgets to inactive sidebar. |
1390 // Move any left over widgets to inactive sidebar. |
1337 foreach ( $existing_sidebars_widgets as $widgets ) { |
1391 foreach ( $existing_sidebars_widgets as $widgets ) { |
1338 if ( is_array( $widgets ) && ! empty( $widgets ) ) { |
1392 if ( is_array( $widgets ) && ! empty( $widgets ) ) { |
1388 } else { |
1442 } else { |
1389 |
1443 |
1390 // ...otherwise remove it from the old sidebar and keep it in the new one. |
1444 // ...otherwise remove it from the old sidebar and keep it in the new one. |
1391 unset( $old_sidebars_widgets[ $old_sidebar ][ $key ] ); |
1445 unset( $old_sidebars_widgets[ $old_sidebar ][ $key ] ); |
1392 } |
1446 } |
1393 } // endif ( $active_key ) |
1447 } // End if ( $active_key ). |
1394 } // endforeach ( $old_widgets as $key => $widget_id ) |
1448 } // End foreach ( $old_widgets as $key => $widget_id ). |
1395 } // endforeach ( $new_sidebars_widgets as $new_sidebar => $new_widgets ) |
1449 } // End foreach ( $new_sidebars_widgets as $new_sidebar => $new_widgets ). |
1396 } // endforeach ( $old_sidebars_widgets as $old_sidebar => $old_widgets ) |
1450 } // End foreach ( $old_sidebars_widgets as $old_sidebar => $old_widgets ). |
1397 } // endif ( ! empty( $old_sidebars_widgets ) ) |
1451 } // End if ( ! empty( $old_sidebars_widgets ) ). |
1398 |
1452 |
1399 // Restore widget settings from when theme was previously active. |
1453 // Restore widget settings from when theme was previously active. |
1400 $new_sidebars_widgets = array_merge( $new_sidebars_widgets, $old_sidebars_widgets ); |
1454 $new_sidebars_widgets = array_merge( $new_sidebars_widgets, $old_sidebars_widgets ); |
1401 } |
1455 } |
1402 |
1456 |
1403 return $new_sidebars_widgets; |
1457 return $new_sidebars_widgets; |
1404 } |
1458 } |
1405 |
1459 |
1406 /** |
1460 /** |
1407 * Compares a list of sidebars with their widgets against a whitelist. |
1461 * Compares a list of sidebars with their widgets against an allowed list. |
1408 * |
1462 * |
1409 * @since 4.9.0 |
1463 * @since 4.9.0 |
1410 * |
1464 * |
1411 * @param array $sidebars_widgets List of sidebars and their widget instance IDs. |
1465 * @param array $sidebars_widgets List of sidebars and their widget instance IDs. |
1412 * @param array $whitelist Optional. List of widget IDs to compare against. Default: Registered widgets. |
1466 * @param array $allowed_widget_ids Optional. List of widget IDs to compare against. Default: Registered widgets. |
1413 * @return array Sidebars with whitelisted widgets. |
1467 * @return array Sidebars with allowed widgets. |
1414 */ |
1468 */ |
1415 function _wp_remove_unregistered_widgets( $sidebars_widgets, $whitelist = array() ) { |
1469 function _wp_remove_unregistered_widgets( $sidebars_widgets, $allowed_widget_ids = array() ) { |
1416 if ( empty( $whitelist ) ) { |
1470 if ( empty( $allowed_widget_ids ) ) { |
1417 $whitelist = array_keys( $GLOBALS['wp_registered_widgets'] ); |
1471 $allowed_widget_ids = array_keys( $GLOBALS['wp_registered_widgets'] ); |
1418 } |
1472 } |
1419 |
1473 |
1420 foreach ( $sidebars_widgets as $sidebar => $widgets ) { |
1474 foreach ( $sidebars_widgets as $sidebar => $widgets ) { |
1421 if ( is_array( $widgets ) ) { |
1475 if ( is_array( $widgets ) ) { |
1422 $sidebars_widgets[ $sidebar ] = array_intersect( $widgets, $whitelist ); |
1476 $sidebars_widgets[ $sidebar ] = array_intersect( $widgets, $allowed_widget_ids ); |
1423 } |
1477 } |
1424 } |
1478 } |
1425 |
1479 |
1426 return $sidebars_widgets; |
1480 return $sidebars_widgets; |
1427 } |
1481 } |
1429 /** |
1483 /** |
1430 * Display the RSS entries in a list. |
1484 * Display the RSS entries in a list. |
1431 * |
1485 * |
1432 * @since 2.5.0 |
1486 * @since 2.5.0 |
1433 * |
1487 * |
1434 * @param string|array|object $rss RSS url. |
1488 * @param string|array|object $rss RSS url. |
1435 * @param array $args Widget arguments. |
1489 * @param array $args Widget arguments. |
1436 */ |
1490 */ |
1437 function wp_widget_rss_output( $rss, $args = array() ) { |
1491 function wp_widget_rss_output( $rss, $args = array() ) { |
1438 if ( is_string( $rss ) ) { |
1492 if ( is_string( $rss ) ) { |
1439 $rss = fetch_feed( $rss ); |
1493 $rss = fetch_feed( $rss ); |
1440 } elseif ( is_array( $rss ) && isset( $rss['url'] ) ) { |
1494 } elseif ( is_array( $rss ) && isset( $rss['url'] ) ) { |
1475 } |
1529 } |
1476 |
1530 |
1477 echo '<ul>'; |
1531 echo '<ul>'; |
1478 foreach ( $rss->get_items( 0, $items ) as $item ) { |
1532 foreach ( $rss->get_items( 0, $items ) as $item ) { |
1479 $link = $item->get_link(); |
1533 $link = $item->get_link(); |
1480 while ( stristr( $link, 'http' ) != $link ) { |
1534 while ( stristr( $link, 'http' ) !== $link ) { |
1481 $link = substr( $link, 1 ); |
1535 $link = substr( $link, 1 ); |
1482 } |
1536 } |
1483 $link = esc_url( strip_tags( $link ) ); |
1537 $link = esc_url( strip_tags( $link ) ); |
1484 |
1538 |
1485 $title = esc_html( trim( strip_tags( $item->get_title() ) ) ); |
1539 $title = esc_html( trim( strip_tags( $item->get_title() ) ) ); |
1486 if ( empty( $title ) ) { |
1540 if ( empty( $title ) ) { |
1487 $title = __( 'Untitled' ); |
1541 $title = __( 'Untitled' ); |
1488 } |
1542 } |
1489 |
1543 |
1490 $desc = @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) ); |
1544 $desc = html_entity_decode( $item->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) ); |
1491 $desc = esc_attr( wp_trim_words( $desc, 55, ' […]' ) ); |
1545 $desc = esc_attr( wp_trim_words( $desc, 55, ' […]' ) ); |
1492 |
1546 |
1493 $summary = ''; |
1547 $summary = ''; |
1494 if ( $show_summary ) { |
1548 if ( $show_summary ) { |
1495 $summary = $desc; |
1549 $summary = $desc; |
1496 |
1550 |
1497 // Change existing [...] to […]. |
1551 // Change existing [...] to […]. |
1498 if ( '[...]' == substr( $summary, -5 ) ) { |
1552 if ( '[...]' === substr( $summary, -5 ) ) { |
1499 $summary = substr( $summary, 0, -5 ) . '[…]'; |
1553 $summary = substr( $summary, 0, -5 ) . '[…]'; |
1500 } |
1554 } |
1501 |
1555 |
1502 $summary = '<div class="rssSummary">' . esc_html( $summary ) . '</div>'; |
1556 $summary = '<div class="rssSummary">' . esc_html( $summary ) . '</div>'; |
1503 } |
1557 } |
1518 $author = $author->get_name(); |
1572 $author = $author->get_name(); |
1519 $author = ' <cite>' . esc_html( strip_tags( $author ) ) . '</cite>'; |
1573 $author = ' <cite>' . esc_html( strip_tags( $author ) ) . '</cite>'; |
1520 } |
1574 } |
1521 } |
1575 } |
1522 |
1576 |
1523 if ( $link == '' ) { |
1577 if ( '' === $link ) { |
1524 echo "<li>$title{$date}{$summary}{$author}</li>"; |
1578 echo "<li>$title{$date}{$summary}{$author}</li>"; |
1525 } elseif ( $show_summary ) { |
1579 } elseif ( $show_summary ) { |
1526 echo "<li><a class='rsswidget' href='$link'>$title</a>{$date}{$summary}{$author}</li>"; |
1580 echo "<li><a class='rsswidget' href='$link'>$title</a>{$date}{$summary}{$author}</li>"; |
1527 } else { |
1581 } else { |
1528 echo "<li><a class='rsswidget' href='$link'>$title</a>{$date}{$author}</li>"; |
1582 echo "<li><a class='rsswidget' href='$link'>$title</a>{$date}{$author}</li>"; |
1540 * and are as follows: 'url', 'title', 'items', 'show_summary', 'show_author', |
1594 * and are as follows: 'url', 'title', 'items', 'show_summary', 'show_author', |
1541 * 'show_date'. |
1595 * 'show_date'. |
1542 * |
1596 * |
1543 * @since 2.5.0 |
1597 * @since 2.5.0 |
1544 * |
1598 * |
1545 * @param array|string $args Values for input fields. |
1599 * @param array|string $args Values for input fields. |
1546 * @param array $inputs Override default display options. |
1600 * @param array $inputs Override default display options. |
1547 */ |
1601 */ |
1548 function wp_widget_rss_form( $args, $inputs = null ) { |
1602 function wp_widget_rss_form( $args, $inputs = null ) { |
1549 $default_inputs = array( |
1603 $default_inputs = array( |
1550 'url' => true, |
1604 'url' => true, |
1551 'title' => true, |
1605 'title' => true, |
1587 for ( $i = 1; $i <= 20; ++$i ) { |
1641 for ( $i = 1; $i <= 20; ++$i ) { |
1588 echo "<option value='$i' " . selected( $args['items'], $i, false ) . ">$i</option>"; |
1642 echo "<option value='$i' " . selected( $args['items'], $i, false ) . ">$i</option>"; |
1589 } |
1643 } |
1590 ?> |
1644 ?> |
1591 </select></p> |
1645 </select></p> |
1592 <?php endif; if ( $inputs['show_summary'] ) : ?> |
1646 <?php endif; if ( $inputs['show_summary'] || $inputs['show_author'] || $inputs['show_date'] ) : ?> |
1593 <p><input id="rss-show-summary-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][show_summary]" type="checkbox" value="1" <?php checked( $args['show_summary'] ); ?> /> |
1647 <p> |
1594 <label for="rss-show-summary-<?php echo $esc_number; ?>"><?php _e( 'Display item content?' ); ?></label></p> |
1648 <?php if ( $inputs['show_summary'] ) : ?> |
1595 <?php endif; if ( $inputs['show_author'] ) : ?> |
1649 <input id="rss-show-summary-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][show_summary]" type="checkbox" value="1" <?php checked( $args['show_summary'] ); ?> /> |
1596 <p><input id="rss-show-author-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][show_author]" type="checkbox" value="1" <?php checked( $args['show_author'] ); ?> /> |
1650 <label for="rss-show-summary-<?php echo $esc_number; ?>"><?php _e( 'Display item content?' ); ?></label><br /> |
1597 <label for="rss-show-author-<?php echo $esc_number; ?>"><?php _e( 'Display item author if available?' ); ?></label></p> |
1651 <?php endif; if ( $inputs['show_author'] ) : ?> |
1598 <?php endif; if ( $inputs['show_date'] ) : ?> |
1652 <input id="rss-show-author-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][show_author]" type="checkbox" value="1" <?php checked( $args['show_author'] ); ?> /> |
1599 <p><input id="rss-show-date-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][show_date]" type="checkbox" value="1" <?php checked( $args['show_date'] ); ?>/> |
1653 <label for="rss-show-author-<?php echo $esc_number; ?>"><?php _e( 'Display item author if available?' ); ?></label><br /> |
1600 <label for="rss-show-date-<?php echo $esc_number; ?>"><?php _e( 'Display item date?' ); ?></label></p> |
1654 <?php endif; if ( $inputs['show_date'] ) : ?> |
|
1655 <input id="rss-show-date-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][show_date]" type="checkbox" value="1" <?php checked( $args['show_date'] ); ?>/> |
|
1656 <label for="rss-show-date-<?php echo $esc_number; ?>"><?php _e( 'Display item date?' ); ?></label><br /> |
|
1657 <?php endif; ?> |
|
1658 </p> |
1601 <?php |
1659 <?php |
1602 endif; |
1660 endif; // End of display options. |
1603 foreach ( array_keys( $default_inputs ) as $input ) : |
1661 foreach ( array_keys( $default_inputs ) as $input ) : |
1604 if ( 'hidden' === $inputs[ $input ] ) : |
1662 if ( 'hidden' === $inputs[ $input ] ) : |
1605 $id = str_replace( '_', '-', $input ); |
1663 $id = str_replace( '_', '-', $input ); |
1606 ?> |
1664 ?> |
1607 <input type="hidden" id="rss-<?php echo esc_attr( $id ); ?>-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][<?php echo esc_attr( $input ); ?>]" value="<?php echo esc_attr( $args[ $input ] ); ?>" /> |
1665 <input type="hidden" id="rss-<?php echo esc_attr( $id ); ?>-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][<?php echo esc_attr( $input ); ?>]" value="<?php echo esc_attr( $args[ $input ] ); ?>" /> |
1621 * All respectively in the order of the array elements. |
1679 * All respectively in the order of the array elements. |
1622 * |
1680 * |
1623 * @since 2.5.0 |
1681 * @since 2.5.0 |
1624 * |
1682 * |
1625 * @param array $widget_rss RSS widget feed data. Expects unescaped data. |
1683 * @param array $widget_rss RSS widget feed data. Expects unescaped data. |
1626 * @param bool $check_feed Optional, default is true. Whether to check feed for errors. |
1684 * @param bool $check_feed Optional. Whether to check feed for errors. Default true. |
1627 * @return array |
1685 * @return array |
1628 */ |
1686 */ |
1629 function wp_widget_rss_process( $widget_rss, $check_feed = true ) { |
1687 function wp_widget_rss_process( $widget_rss, $check_feed = true ) { |
1630 $items = (int) $widget_rss['items']; |
1688 $items = (int) $widget_rss['items']; |
1631 if ( $items < 1 || 20 < $items ) { |
1689 if ( $items < 1 || 20 < $items ) { |
1643 $link = ''; |
1701 $link = ''; |
1644 if ( is_wp_error( $rss ) ) { |
1702 if ( is_wp_error( $rss ) ) { |
1645 $error = $rss->get_error_message(); |
1703 $error = $rss->get_error_message(); |
1646 } else { |
1704 } else { |
1647 $link = esc_url( strip_tags( $rss->get_permalink() ) ); |
1705 $link = esc_url( strip_tags( $rss->get_permalink() ) ); |
1648 while ( stristr( $link, 'http' ) != $link ) { |
1706 while ( stristr( $link, 'http' ) !== $link ) { |
1649 $link = substr( $link, 1 ); |
1707 $link = substr( $link, 1 ); |
1650 } |
1708 } |
1651 |
1709 |
1652 $rss->__destruct(); |
1710 $rss->__destruct(); |
1653 unset( $rss ); |
1711 unset( $rss ); |