wp/wp-includes/widgets.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
     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://wordpress.org/support/article/wordpress-widgets/
    13  * @link https://wordpress.org/documentation/article/manage-wordpress-widgets/
    14  * @link https://developer.wordpress.org/themes/functionality/widgets/
    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
    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 
    28 /**
    28 /**
    29  * Stores the sidebars, since many themes can have more than one.
    29  * Stores the sidebars, since many themes can have more than one.
    30  *
    30  *
    31  * @global array $wp_registered_sidebars Registered sidebars.
       
    32  * @since 2.2.0
    31  * @since 2.2.0
       
    32  *
       
    33  * @global array $wp_registered_sidebars The registered sidebars.
    33  */
    34  */
    34 $wp_registered_sidebars = array();
    35 $wp_registered_sidebars = array();
    35 
    36 
    36 /**
    37 /**
    37  * Stores the registered widgets.
    38  * Stores the registered widgets.
    38  *
    39  *
    39  * @global array $wp_registered_widgets
       
    40  * @since 2.2.0
    40  * @since 2.2.0
       
    41  *
       
    42  * @global array $wp_registered_widgets The registered widgets.
    41  */
    43  */
    42 $wp_registered_widgets = array();
    44 $wp_registered_widgets = array();
    43 
    45 
    44 /**
    46 /**
    45  * Stores the registered widget controls (options).
    47  * Stores the registered widget controls (options).
    46  *
    48  *
    47  * @global array $wp_registered_widget_controls
       
    48  * @since 2.2.0
    49  * @since 2.2.0
       
    50  *
       
    51  * @global array $wp_registered_widget_controls The registered widget controls.
    49  */
    52  */
    50 $wp_registered_widget_controls = array();
    53 $wp_registered_widget_controls = array();
    51 /**
    54 
    52  * @global array $wp_registered_widget_updates
    55 /**
       
    56  * Stores the registered widget updates.
       
    57  *
       
    58  * @since 2.8.0
       
    59  *
       
    60  * @global array $wp_registered_widget_updates The registered widget updates.
    53  */
    61  */
    54 $wp_registered_widget_updates = array();
    62 $wp_registered_widget_updates = array();
    55 
    63 
    56 /**
    64 /**
    57  * Private
    65  * Private
   183 			}
   191 			}
   184 		} else {
   192 		} else {
   185 			$_args['name'] = isset( $args['name'] ) ? $args['name'] : __( 'Sidebar' );
   193 			$_args['name'] = isset( $args['name'] ) ? $args['name'] : __( 'Sidebar' );
   186 		}
   194 		}
   187 
   195 
   188 		// Custom specified ID's are suffixed if they exist already.
   196 		/*
   189 		// Automatically generated sidebar names need to be suffixed regardless starting at -0.
   197 		 * Custom specified ID's are suffixed if they exist already.
       
   198 		 * Automatically generated sidebar names need to be suffixed regardless starting at -0.
       
   199 		 */
   190 		if ( isset( $args['id'] ) ) {
   200 		if ( isset( $args['id'] ) ) {
   191 			$_args['id'] = $args['id'];
   201 			$_args['id'] = $args['id'];
   192 			$n           = 2; // Start at -2 for conflicting custom IDs.
   202 			$n           = 2; // Start at -2 for conflicting custom IDs.
   193 			while ( is_registered_sidebar( $_args['id'] ) ) {
   203 			while ( is_registered_sidebar( $_args['id'] ) ) {
   194 				$_args['id'] = $args['id'] . '-' . $n++;
   204 				$_args['id'] = $args['id'] . '-' . $n++;
   220  *
   230  *
   221  * @since 2.2.0
   231  * @since 2.2.0
   222  * @since 5.6.0 Added the `before_sidebar` and `after_sidebar` arguments.
   232  * @since 5.6.0 Added the `before_sidebar` and `after_sidebar` arguments.
   223  * @since 5.9.0 Added the `show_in_rest` argument.
   233  * @since 5.9.0 Added the `show_in_rest` argument.
   224  *
   234  *
   225  * @global array $wp_registered_sidebars Registered sidebars.
   235  * @global array $wp_registered_sidebars The registered sidebars.
   226  *
   236  *
   227  * @param array|string $args {
   237  * @param array|string $args {
   228  *     Optional. Array or string of arguments for the sidebar being registered.
   238  *     Optional. Array or string of arguments for the sidebar being registered.
   229  *
   239  *
   230  *     @type string $name           The name or title of the sidebar displayed in the Widgets
   240  *     @type string $name           The name or title of the sidebar displayed in the Widgets
   322 /**
   332 /**
   323  * Removes a sidebar from the list.
   333  * Removes a sidebar from the list.
   324  *
   334  *
   325  * @since 2.2.0
   335  * @since 2.2.0
   326  *
   336  *
   327  * @global array $wp_registered_sidebars Registered sidebars.
   337  * @global array $wp_registered_sidebars The registered sidebars.
   328  *
   338  *
   329  * @param string|int $sidebar_id The ID of the sidebar when it was registered.
   339  * @param string|int $sidebar_id The ID of the sidebar when it was registered.
   330  */
   340  */
   331 function unregister_sidebar( $sidebar_id ) {
   341 function unregister_sidebar( $sidebar_id ) {
   332 	global $wp_registered_sidebars;
   342 	global $wp_registered_sidebars;
   337 /**
   347 /**
   338  * Checks if a sidebar is registered.
   348  * Checks if a sidebar is registered.
   339  *
   349  *
   340  * @since 4.4.0
   350  * @since 4.4.0
   341  *
   351  *
   342  * @global array $wp_registered_sidebars Registered sidebars.
   352  * @global array $wp_registered_sidebars The registered sidebars.
   343  *
   353  *
   344  * @param string|int $sidebar_id The ID of the sidebar when it was registered.
   354  * @param string|int $sidebar_id The ID of the sidebar when it was registered.
   345  * @return bool True if the sidebar is registered, false otherwise.
   355  * @return bool True if the sidebar is registered, false otherwise.
   346  */
   356  */
   347 function is_registered_sidebar( $sidebar_id ) {
   357 function is_registered_sidebar( $sidebar_id ) {
   363  *              by adding it to the function signature.
   373  *              by adding it to the function signature.
   364  * @since 5.8.0 Added show_instance_in_rest option.
   374  * @since 5.8.0 Added show_instance_in_rest option.
   365  *
   375  *
   366  * @global array $wp_registered_widgets            Uses stored registered widgets.
   376  * @global array $wp_registered_widgets            Uses stored registered widgets.
   367  * @global array $wp_registered_widget_controls    Stores the registered widget controls (options).
   377  * @global array $wp_registered_widget_controls    Stores the registered widget controls (options).
   368  * @global array $wp_registered_widget_updates
   378  * @global array $wp_registered_widget_updates     The registered widget updates.
   369  * @global array $_wp_deprecated_widgets_callbacks
   379  * @global array $_wp_deprecated_widgets_callbacks
   370  *
   380  *
   371  * @param int|string $id              Widget ID.
   381  * @param int|string $id              Widget ID.
   372  * @param string     $name            Widget display title.
   382  * @param string     $name            Widget display title.
   373  * @param callable   $output_callback Run when widget is called.
   383  * @param callable   $output_callback Run when widget is called.
   431  * describes the widget for display on the widget administration panel or
   441  * describes the widget for display on the widget administration panel or
   432  * in the theme.
   442  * in the theme.
   433  *
   443  *
   434  * @since 2.5.0
   444  * @since 2.5.0
   435  *
   445  *
   436  * @global array $wp_registered_widgets
   446  * @global array $wp_registered_widgets The registered widgets.
   437  *
   447  *
   438  * @param int|string $id Widget ID.
   448  * @param int|string $id Widget ID.
   439  * @return string|void Widget description, if available.
   449  * @return string|void Widget description, if available.
   440  */
   450  */
   441 function wp_widget_description( $id ) {
   451 function wp_widget_description( $id ) {
   456  * When registering sidebars a 'description' parameter can be included that
   466  * When registering sidebars a 'description' parameter can be included that
   457  * describes the sidebar for display on the widget administration panel.
   467  * describes the sidebar for display on the widget administration panel.
   458  *
   468  *
   459  * @since 2.9.0
   469  * @since 2.9.0
   460  *
   470  *
   461  * @global array $wp_registered_sidebars Registered sidebars.
   471  * @global array $wp_registered_sidebars The registered sidebars.
   462  *
   472  *
   463  * @param string $id sidebar ID.
   473  * @param string $id sidebar ID.
   464  * @return string|void Sidebar description, if available.
   474  * @return string|void Sidebar description, if available.
   465  */
   475  */
   466 function wp_sidebar_description( $id ) {
   476 function wp_sidebar_description( $id ) {
   502  *
   512  *
   503  * @since 2.2.0
   513  * @since 2.2.0
   504  * @since 5.3.0 Formalized the existing and already documented `...$params` parameter
   514  * @since 5.3.0 Formalized the existing and already documented `...$params` parameter
   505  *              by adding it to the function signature.
   515  *              by adding it to the function signature.
   506  *
   516  *
   507  * @global array $wp_registered_widget_controls
   517  * @global array $wp_registered_widget_controls The registered widget controls.
   508  * @global array $wp_registered_widget_updates
   518  * @global array $wp_registered_widget_updates  The registered widget updates.
   509  * @global array $wp_registered_widgets
   519  * @global array $wp_registered_widgets         The registered widgets.
   510  * @global array $_wp_deprecated_widgets_callbacks
   520  * @global array $_wp_deprecated_widgets_callbacks
   511  *
   521  *
   512  * @param int|string $id               Sidebar ID.
   522  * @param int|string $id               Sidebar ID.
   513  * @param string     $name             Sidebar display name.
   523  * @param string     $name             Sidebar display name.
   514  * @param callable   $control_callback Run when sidebar is displayed.
   524  * @param callable   $control_callback Run when sidebar is displayed.
   579  *
   589  *
   580  * @since 2.8.0
   590  * @since 2.8.0
   581  * @since 5.3.0 Formalized the existing and already documented `...$params` parameter
   591  * @since 5.3.0 Formalized the existing and already documented `...$params` parameter
   582  *              by adding it to the function signature.
   592  *              by adding it to the function signature.
   583  *
   593  *
   584  * @global array $wp_registered_widget_updates
   594  * @global array $wp_registered_widget_updates The registered widget updates.
   585  *
   595  *
   586  * @param string   $id_base         The base ID of a widget created by extending WP_Widget.
   596  * @param string   $id_base         The base ID of a widget created by extending WP_Widget.
   587  * @param callable $update_callback Update callback method for the widget.
   597  * @param callable $update_callback Update callback method for the widget.
   588  * @param array    $options         Optional. Widget control options. See wp_register_widget_control().
   598  * @param array    $options         Optional. Widget control options. See wp_register_widget_control().
   589  *                                  Default empty array.
   599  *                                  Default empty array.
   613  *
   623  *
   614  * @since 2.8.0
   624  * @since 2.8.0
   615  * @since 5.3.0 Formalized the existing and already documented `...$params` parameter
   625  * @since 5.3.0 Formalized the existing and already documented `...$params` parameter
   616  *              by adding it to the function signature.
   626  *              by adding it to the function signature.
   617  *
   627  *
   618  * @global array $wp_registered_widget_controls
   628  * @global array $wp_registered_widget_controls The registered widget controls.
   619  *
   629  *
   620  * @param int|string $id            Widget ID.
   630  * @param int|string $id            Widget ID.
   621  * @param string     $name          Name attribute for the widget.
   631  * @param string     $name          Name attribute for the widget.
   622  * @param callable   $form_callback Form callback.
   632  * @param callable   $form_callback Form callback.
   623  * @param array      $options       Optional. Widget control options. See wp_register_widget_control().
   633  * @param array      $options       Optional. Widget control options. See wp_register_widget_control().
   676  * 'name' parameter for its registered sidebars you can pass an ID or name as the $index parameter.
   686  * 'name' parameter for its registered sidebars you can pass an ID or name as the $index parameter.
   677  * Otherwise, you can pass in a numerical index to display the sidebar at that index.
   687  * Otherwise, you can pass in a numerical index to display the sidebar at that index.
   678  *
   688  *
   679  * @since 2.2.0
   689  * @since 2.2.0
   680  *
   690  *
   681  * @global array $wp_registered_sidebars Registered sidebars.
   691  * @global array $wp_registered_sidebars The registered sidebars.
   682  * @global array $wp_registered_widgets  Registered widgets.
   692  * @global array $wp_registered_widgets  The registered widgets.
   683  *
   693  *
   684  * @param int|string $index Optional. Index, name or ID of dynamic sidebar. Default 1.
   694  * @param int|string $index Optional. Index, name or ID of dynamic sidebar. Default 1.
   685  * @return bool True, if widget sidebar was found and called. False if not found or not called.
   695  * @return bool True, if widget sidebar was found and called. False if not found or not called.
   686  */
   696  */
   687 function dynamic_sidebar( $index = 1 ) {
   697 function dynamic_sidebar( $index = 1 ) {
   887  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
   897  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
   888  * Conditional Tags} article in the Theme Developer Handbook.
   898  * Conditional Tags} article in the Theme Developer Handbook.
   889  *
   899  *
   890  * @since 2.2.0
   900  * @since 2.2.0
   891  *
   901  *
   892  * @global array $wp_registered_widgets
   902  * @global array $wp_registered_widgets The registered widgets.
   893  *
   903  *
   894  * @param callable|false $callback      Optional. Widget callback to check. Default false.
   904  * @param callable|false $callback      Optional. Widget callback to check. Default false.
   895  * @param string|false   $widget_id     Optional. Widget ID. Optional, but needed for checking.
   905  * @param string|false   $widget_id     Optional. Widget ID. Optional, but needed for checking.
   896  *                                      Default false.
   906  *                                      Default false.
   897  * @param string|false   $id_base       Optional. The base ID of a widget created by extending WP_Widget.
   907  * @param string|false   $id_base       Optional. The base ID of a widget created by extending WP_Widget.
   906 
   916 
   907 	$sidebars_widgets = wp_get_sidebars_widgets();
   917 	$sidebars_widgets = wp_get_sidebars_widgets();
   908 
   918 
   909 	if ( is_array( $sidebars_widgets ) ) {
   919 	if ( is_array( $sidebars_widgets ) ) {
   910 		foreach ( $sidebars_widgets as $sidebar => $widgets ) {
   920 		foreach ( $sidebars_widgets as $sidebar => $widgets ) {
   911 			if ( $skip_inactive && ( 'wp_inactive_widgets' === $sidebar || 'orphaned_widgets' === substr( $sidebar, 0, 16 ) ) ) {
   921 			if ( $skip_inactive && ( 'wp_inactive_widgets' === $sidebar || str_starts_with( $sidebar, 'orphaned_widgets' ) ) ) {
   912 				continue;
   922 				continue;
   913 			}
   923 			}
   914 
   924 
   915 			if ( is_array( $widgets ) ) {
   925 			if ( is_array( $widgets ) ) {
   916 				foreach ( $widgets as $widget ) {
   926 				foreach ( $widgets as $widget ) {
   933  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
   943  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
   934  * Conditional Tags} article in the Theme Developer Handbook.
   944  * Conditional Tags} article in the Theme Developer Handbook.
   935  *
   945  *
   936  * @since 2.2.0
   946  * @since 2.2.0
   937  *
   947  *
   938  * @global array $wp_registered_widgets  Registered widgets.
   948  * @global array $wp_registered_widgets  The registered widgets.
   939  * @global array $wp_registered_sidebars Registered sidebars.
   949  * @global array $wp_registered_sidebars The registered sidebars.
   940  *
   950  *
   941  * @return bool True if using widgets, false otherwise.
   951  * @return bool True if using widgets, false otherwise.
   942  */
   952  */
   943 function is_dynamic_sidebar() {
   953 function is_dynamic_sidebar() {
   944 	global $wp_registered_widgets, $wp_registered_sidebars;
   954 	global $wp_registered_widgets, $wp_registered_sidebars;
  1011 		_deprecated_argument( __FUNCTION__, '2.8.1' );
  1021 		_deprecated_argument( __FUNCTION__, '2.8.1' );
  1012 	}
  1022 	}
  1013 
  1023 
  1014 	global $_wp_sidebars_widgets, $sidebars_widgets;
  1024 	global $_wp_sidebars_widgets, $sidebars_widgets;
  1015 
  1025 
  1016 	// If loading from front page, consult $_wp_sidebars_widgets rather than options
  1026 	/*
  1017 	// to see if wp_convert_widget_settings() has made manipulations in memory.
  1027 	 * If loading from front page, consult $_wp_sidebars_widgets rather than options
       
  1028 	 * to see if wp_convert_widget_settings() has made manipulations in memory.
       
  1029 	 */
  1018 	if ( ! is_admin() ) {
  1030 	if ( ! is_admin() ) {
  1019 		if ( empty( $_wp_sidebars_widgets ) ) {
  1031 		if ( empty( $_wp_sidebars_widgets ) ) {
  1020 			$_wp_sidebars_widgets = get_option( 'sidebars_widgets', array() );
  1032 			$_wp_sidebars_widgets = get_option( 'sidebars_widgets', array() );
  1021 		}
  1033 		}
  1022 
  1034 
  1094  * Retrieve default registered sidebars list.
  1106  * Retrieve default registered sidebars list.
  1095  *
  1107  *
  1096  * @since 2.2.0
  1108  * @since 2.2.0
  1097  * @access private
  1109  * @access private
  1098  *
  1110  *
  1099  * @global array $wp_registered_sidebars Registered sidebars.
  1111  * @global array $wp_registered_sidebars The registered sidebars.
  1100  *
  1112  *
  1101  * @return array
  1113  * @return array
  1102  */
  1114  */
  1103 function wp_get_widget_defaults() {
  1115 function wp_get_widget_defaults() {
  1104 	global $wp_registered_sidebars;
  1116 	global $wp_registered_sidebars;
  1300  * and the global `$sidebars_widgets`. For that reason it should not be run on front end,
  1312  * and the global `$sidebars_widgets`. For that reason it should not be run on front end,
  1301  * unless the `$theme_changed` value is 'customize' (to bypass the database write).
  1313  * unless the `$theme_changed` value is 'customize' (to bypass the database write).
  1302  *
  1314  *
  1303  * @since 2.8.0
  1315  * @since 2.8.0
  1304  *
  1316  *
  1305  * @global array $wp_registered_sidebars Registered sidebars.
  1317  * @global array $wp_registered_sidebars The registered sidebars.
  1306  * @global array $sidebars_widgets
  1318  * @global array $sidebars_widgets
  1307  * @global array $wp_registered_widgets  Registered widgets.
  1319  * @global array $wp_registered_widgets  The registered widgets.
  1308  *
  1320  *
  1309  * @param string|bool $theme_changed Whether the theme was changed as a boolean. A value
  1321  * @param string|bool $theme_changed Whether the theme was changed as a boolean. A value
  1310  *                                   of 'customize' defers updates for the Customizer.
  1322  *                                   of 'customize' defers updates for the Customizer.
  1311  * @return array Updated sidebars widgets.
  1323  * @return array Updated sidebars widgets.
  1312  */
  1324  */
  1364  * Compares a list of sidebars with their widgets against an allowed list.
  1376  * Compares a list of sidebars with their widgets against an allowed list.
  1365  *
  1377  *
  1366  * @since 4.9.0
  1378  * @since 4.9.0
  1367  * @since 4.9.2 Always tries to restore widget assignments from previous data, not just if sidebars needed mapping.
  1379  * @since 4.9.2 Always tries to restore widget assignments from previous data, not just if sidebars needed mapping.
  1368  *
  1380  *
       
  1381  * @global array $wp_registered_sidebars The registered sidebars.
       
  1382  *
  1369  * @param array $existing_sidebars_widgets List of sidebars and their widget instance IDs.
  1383  * @param array $existing_sidebars_widgets List of sidebars and their widget instance IDs.
  1370  * @return array Mapped sidebars widgets.
  1384  * @return array Mapped sidebars widgets.
  1371  */
  1385  */
  1372 function wp_map_sidebars_widgets( $existing_sidebars_widgets ) {
  1386 function wp_map_sidebars_widgets( $existing_sidebars_widgets ) {
  1373 	global $wp_registered_sidebars;
  1387 	global $wp_registered_sidebars;
  1380 	if ( ! is_array( $existing_sidebars_widgets ) || empty( $existing_sidebars_widgets ) ) {
  1394 	if ( ! is_array( $existing_sidebars_widgets ) || empty( $existing_sidebars_widgets ) ) {
  1381 		return $new_sidebars_widgets;
  1395 		return $new_sidebars_widgets;
  1382 	}
  1396 	}
  1383 
  1397 
  1384 	foreach ( $existing_sidebars_widgets as $sidebar => $widgets ) {
  1398 	foreach ( $existing_sidebars_widgets as $sidebar => $widgets ) {
  1385 		if ( 'wp_inactive_widgets' === $sidebar || 'orphaned_widgets' === substr( $sidebar, 0, 16 ) ) {
  1399 		if ( 'wp_inactive_widgets' === $sidebar || str_starts_with( $sidebar, 'orphaned_widgets' ) ) {
  1386 			$new_sidebars_widgets['wp_inactive_widgets'] = array_merge( $new_sidebars_widgets['wp_inactive_widgets'], (array) $widgets );
  1400 			$new_sidebars_widgets['wp_inactive_widgets'] = array_merge( $new_sidebars_widgets['wp_inactive_widgets'], (array) $widgets );
  1387 			unset( $existing_sidebars_widgets[ $sidebar ] );
  1401 			unset( $existing_sidebars_widgets[ $sidebar ] );
  1388 		}
  1402 		}
  1389 	}
  1403 	}
  1390 
  1404 
  1488 			}
  1502 			}
  1489 		}
  1503 		}
  1490 
  1504 
  1491 		// Remove orphaned widgets, we're only interested in previously active sidebars.
  1505 		// Remove orphaned widgets, we're only interested in previously active sidebars.
  1492 		foreach ( $old_sidebars_widgets as $sidebar => $widgets ) {
  1506 		foreach ( $old_sidebars_widgets as $sidebar => $widgets ) {
  1493 			if ( 'orphaned_widgets' === substr( $sidebar, 0, 16 ) ) {
  1507 			if ( str_starts_with( $sidebar, 'orphaned_widgets' ) ) {
  1494 				unset( $old_sidebars_widgets[ $sidebar ] );
  1508 				unset( $old_sidebars_widgets[ $sidebar ] );
  1495 			}
  1509 			}
  1496 		}
  1510 		}
  1497 
  1511 
  1498 		$old_sidebars_widgets = _wp_remove_unregistered_widgets( $old_sidebars_widgets );
  1512 		$old_sidebars_widgets = _wp_remove_unregistered_widgets( $old_sidebars_widgets );
  1538 /**
  1552 /**
  1539  * Compares a list of sidebars with their widgets against an allowed list.
  1553  * Compares a list of sidebars with their widgets against an allowed list.
  1540  *
  1554  *
  1541  * @since 4.9.0
  1555  * @since 4.9.0
  1542  *
  1556  *
       
  1557  * @global array $wp_registered_widgets The registered widgets.
       
  1558  *
  1543  * @param array $sidebars_widgets   List of sidebars and their widget instance IDs.
  1559  * @param array $sidebars_widgets   List of sidebars and their widget instance IDs.
  1544  * @param array $allowed_widget_ids Optional. List of widget IDs to compare against. Default: Registered widgets.
  1560  * @param array $allowed_widget_ids Optional. List of widget IDs to compare against. Default: Registered widgets.
  1545  * @return array Sidebars with allowed widgets.
  1561  * @return array Sidebars with allowed widgets.
  1546  */
  1562  */
  1547 function _wp_remove_unregistered_widgets( $sidebars_widgets, $allowed_widget_ids = array() ) {
  1563 function _wp_remove_unregistered_widgets( $sidebars_widgets, $allowed_widget_ids = array() ) {
  1576 		return;
  1592 		return;
  1577 	}
  1593 	}
  1578 
  1594 
  1579 	if ( is_wp_error( $rss ) ) {
  1595 	if ( is_wp_error( $rss ) ) {
  1580 		if ( is_admin() || current_user_can( 'manage_options' ) ) {
  1596 		if ( is_admin() || current_user_can( 'manage_options' ) ) {
  1581 			echo '<p><strong>' . __( 'RSS Error:' ) . '</strong> ' . $rss->get_error_message() . '</p>';
  1597 			echo '<p><strong>' . __( 'RSS Error:' ) . '</strong> ' . esc_html( $rss->get_error_message() ) . '</p>';
  1582 		}
  1598 		}
  1583 		return;
  1599 		return;
  1584 	}
  1600 	}
  1585 
  1601 
  1586 	$default_args = array(
  1602 	$default_args = array(
  1625 		$summary = '';
  1641 		$summary = '';
  1626 		if ( $show_summary ) {
  1642 		if ( $show_summary ) {
  1627 			$summary = $desc;
  1643 			$summary = $desc;
  1628 
  1644 
  1629 			// Change existing [...] to [&hellip;].
  1645 			// Change existing [...] to [&hellip;].
  1630 			if ( '[...]' === substr( $summary, -5 ) ) {
  1646 			if ( str_ends_with( $summary, '[...]' ) ) {
  1631 				$summary = substr( $summary, 0, -5 ) . '[&hellip;]';
  1647 				$summary = substr( $summary, 0, -5 ) . '[&hellip;]';
  1632 			}
  1648 			}
  1633 
  1649 
  1634 			$summary = '<div class="rssSummary">' . esc_html( $summary ) . '</div>';
  1650 			$summary = '<div class="rssSummary">' . esc_html( $summary ) . '</div>';
  1635 		}
  1651 		}
  1699 	$args['show_summary'] = isset( $args['show_summary'] ) ? (int) $args['show_summary'] : (int) $inputs['show_summary'];
  1715 	$args['show_summary'] = isset( $args['show_summary'] ) ? (int) $args['show_summary'] : (int) $inputs['show_summary'];
  1700 	$args['show_author']  = isset( $args['show_author'] ) ? (int) $args['show_author'] : (int) $inputs['show_author'];
  1716 	$args['show_author']  = isset( $args['show_author'] ) ? (int) $args['show_author'] : (int) $inputs['show_author'];
  1701 	$args['show_date']    = isset( $args['show_date'] ) ? (int) $args['show_date'] : (int) $inputs['show_date'];
  1717 	$args['show_date']    = isset( $args['show_date'] ) ? (int) $args['show_date'] : (int) $inputs['show_date'];
  1702 
  1718 
  1703 	if ( ! empty( $args['error'] ) ) {
  1719 	if ( ! empty( $args['error'] ) ) {
  1704 		echo '<p class="widget-error"><strong>' . __( 'RSS Error:' ) . '</strong> ' . $args['error'] . '</p>';
  1720 		echo '<p class="widget-error"><strong>' . __( 'RSS Error:' ) . '</strong> ' . esc_html( $args['error'] ) . '</p>';
  1705 	}
  1721 	}
  1706 
  1722 
  1707 	$esc_number = esc_attr( $args['number'] );
  1723 	$esc_number = esc_attr( $args['number'] );
  1708 	if ( $inputs['url'] ) :
  1724 	if ( $inputs['url'] ) :
  1709 		?>
  1725 		?>
  1765 function wp_widget_rss_process( $widget_rss, $check_feed = true ) {
  1781 function wp_widget_rss_process( $widget_rss, $check_feed = true ) {
  1766 	$items = (int) $widget_rss['items'];
  1782 	$items = (int) $widget_rss['items'];
  1767 	if ( $items < 1 || 20 < $items ) {
  1783 	if ( $items < 1 || 20 < $items ) {
  1768 		$items = 10;
  1784 		$items = 10;
  1769 	}
  1785 	}
  1770 	$url          = esc_url_raw( strip_tags( $widget_rss['url'] ) );
  1786 	$url          = sanitize_url( strip_tags( $widget_rss['url'] ) );
  1771 	$title        = isset( $widget_rss['title'] ) ? trim( strip_tags( $widget_rss['title'] ) ) : '';
  1787 	$title        = isset( $widget_rss['title'] ) ? trim( strip_tags( $widget_rss['title'] ) ) : '';
  1772 	$show_summary = isset( $widget_rss['show_summary'] ) ? (int) $widget_rss['show_summary'] : 0;
  1788 	$show_summary = isset( $widget_rss['show_summary'] ) ? (int) $widget_rss['show_summary'] : 0;
  1773 	$show_author  = isset( $widget_rss['show_author'] ) ? (int) $widget_rss['show_author'] : 0;
  1789 	$show_author  = isset( $widget_rss['show_author'] ) ? (int) $widget_rss['show_author'] : 0;
  1774 	$show_date    = isset( $widget_rss['show_date'] ) ? (int) $widget_rss['show_date'] : 0;
  1790 	$show_date    = isset( $widget_rss['show_date'] ) ? (int) $widget_rss['show_date'] : 0;
  1775 	$error        = false;
  1791 	$error        = false;
  1961 
  1977 
  1962 /**
  1978 /**
  1963  * Calls the render callback of a widget and returns the output.
  1979  * Calls the render callback of a widget and returns the output.
  1964  *
  1980  *
  1965  * @since 5.8.0
  1981  * @since 5.8.0
       
  1982  *
       
  1983  * @global array $wp_registered_widgets  The registered widgets.
       
  1984  * @global array $wp_registered_sidebars The registered sidebars.
  1966  *
  1985  *
  1967  * @param string $widget_id Widget ID.
  1986  * @param string $widget_id Widget ID.
  1968  * @param string $sidebar_id Sidebar ID.
  1987  * @param string $sidebar_id Sidebar ID.
  1969  * @return string
  1988  * @return string
  1970  */
  1989  */
  2027 
  2046 
  2028 /**
  2047 /**
  2029  * Calls the control callback of a widget and returns the output.
  2048  * Calls the control callback of a widget and returns the output.
  2030  *
  2049  *
  2031  * @since 5.8.0
  2050  * @since 5.8.0
       
  2051  *
       
  2052  * @global array $wp_registered_widget_controls The registered widget controls.
  2032  *
  2053  *
  2033  * @param string $id Widget ID.
  2054  * @param string $id Widget ID.
  2034  * @return string|null
  2055  * @return string|null
  2035  */
  2056  */
  2036 function wp_render_widget_control( $id ) {
  2057 function wp_render_widget_control( $id ) {
  2103 				'5.8.0'
  2124 				'5.8.0'
  2104 			);
  2125 			);
  2105 		}
  2126 		}
  2106 	}
  2127 	}
  2107 }
  2128 }
       
  2129 
       
  2130 /**
       
  2131  * Registers the previous theme's sidebars for the block themes.
       
  2132  *
       
  2133  * @since 6.2.0
       
  2134  * @access private
       
  2135  *
       
  2136  * @global array $wp_registered_sidebars The registered sidebars.
       
  2137  */
       
  2138 function _wp_block_theme_register_classic_sidebars() {
       
  2139 	global $wp_registered_sidebars;
       
  2140 
       
  2141 	if ( ! wp_is_block_theme() ) {
       
  2142 		return;
       
  2143 	}
       
  2144 
       
  2145 	$classic_sidebars = get_theme_mod( 'wp_classic_sidebars' );
       
  2146 	if ( empty( $classic_sidebars ) ) {
       
  2147 		return;
       
  2148 	}
       
  2149 
       
  2150 	// Don't use `register_sidebar` since it will enable the `widgets` support for a theme.
       
  2151 	foreach ( $classic_sidebars as $sidebar ) {
       
  2152 		$wp_registered_sidebars[ $sidebar['id'] ] = $sidebar;
       
  2153 	}
       
  2154 }