--- a/wp/wp-includes/widgets.php Thu Sep 29 08:06:27 2022 +0200
+++ b/wp/wp-includes/widgets.php Fri Sep 05 18:40:08 2025 +0200
@@ -10,7 +10,7 @@
* This functionality was found in a plugin before the WordPress 2.2 release, which
* included it in the core from that point on.
*
- * @link https://wordpress.org/support/article/wordpress-widgets/
+ * @link https://wordpress.org/documentation/article/manage-wordpress-widgets/
* @link https://developer.wordpress.org/themes/functionality/widgets/
*
* @package WordPress
@@ -28,28 +28,36 @@
/**
* Stores the sidebars, since many themes can have more than one.
*
- * @global array $wp_registered_sidebars Registered sidebars.
* @since 2.2.0
+ *
+ * @global array $wp_registered_sidebars The registered sidebars.
*/
$wp_registered_sidebars = array();
/**
* Stores the registered widgets.
*
- * @global array $wp_registered_widgets
* @since 2.2.0
+ *
+ * @global array $wp_registered_widgets The registered widgets.
*/
$wp_registered_widgets = array();
/**
* Stores the registered widget controls (options).
*
- * @global array $wp_registered_widget_controls
* @since 2.2.0
+ *
+ * @global array $wp_registered_widget_controls The registered widget controls.
*/
$wp_registered_widget_controls = array();
+
/**
- * @global array $wp_registered_widget_updates
+ * Stores the registered widget updates.
+ *
+ * @since 2.8.0
+ *
+ * @global array $wp_registered_widget_updates The registered widget updates.
*/
$wp_registered_widget_updates = array();
@@ -185,8 +193,10 @@
$_args['name'] = isset( $args['name'] ) ? $args['name'] : __( 'Sidebar' );
}
- // Custom specified ID's are suffixed if they exist already.
- // Automatically generated sidebar names need to be suffixed regardless starting at -0.
+ /*
+ * Custom specified ID's are suffixed if they exist already.
+ * Automatically generated sidebar names need to be suffixed regardless starting at -0.
+ */
if ( isset( $args['id'] ) ) {
$_args['id'] = $args['id'];
$n = 2; // Start at -2 for conflicting custom IDs.
@@ -222,7 +232,7 @@
* @since 5.6.0 Added the `before_sidebar` and `after_sidebar` arguments.
* @since 5.9.0 Added the `show_in_rest` argument.
*
- * @global array $wp_registered_sidebars Registered sidebars.
+ * @global array $wp_registered_sidebars The registered sidebars.
*
* @param array|string $args {
* Optional. Array or string of arguments for the sidebar being registered.
@@ -324,7 +334,7 @@
*
* @since 2.2.0
*
- * @global array $wp_registered_sidebars Registered sidebars.
+ * @global array $wp_registered_sidebars The registered sidebars.
*
* @param string|int $sidebar_id The ID of the sidebar when it was registered.
*/
@@ -339,7 +349,7 @@
*
* @since 4.4.0
*
- * @global array $wp_registered_sidebars Registered sidebars.
+ * @global array $wp_registered_sidebars The registered sidebars.
*
* @param string|int $sidebar_id The ID of the sidebar when it was registered.
* @return bool True if the sidebar is registered, false otherwise.
@@ -365,7 +375,7 @@
*
* @global array $wp_registered_widgets Uses stored registered widgets.
* @global array $wp_registered_widget_controls Stores the registered widget controls (options).
- * @global array $wp_registered_widget_updates
+ * @global array $wp_registered_widget_updates The registered widget updates.
* @global array $_wp_deprecated_widgets_callbacks
*
* @param int|string $id Widget ID.
@@ -433,7 +443,7 @@
*
* @since 2.5.0
*
- * @global array $wp_registered_widgets
+ * @global array $wp_registered_widgets The registered widgets.
*
* @param int|string $id Widget ID.
* @return string|void Widget description, if available.
@@ -458,7 +468,7 @@
*
* @since 2.9.0
*
- * @global array $wp_registered_sidebars Registered sidebars.
+ * @global array $wp_registered_sidebars The registered sidebars.
*
* @param string $id sidebar ID.
* @return string|void Sidebar description, if available.
@@ -504,9 +514,9 @@
* @since 5.3.0 Formalized the existing and already documented `...$params` parameter
* by adding it to the function signature.
*
- * @global array $wp_registered_widget_controls
- * @global array $wp_registered_widget_updates
- * @global array $wp_registered_widgets
+ * @global array $wp_registered_widget_controls The registered widget controls.
+ * @global array $wp_registered_widget_updates The registered widget updates.
+ * @global array $wp_registered_widgets The registered widgets.
* @global array $_wp_deprecated_widgets_callbacks
*
* @param int|string $id Sidebar ID.
@@ -581,7 +591,7 @@
* @since 5.3.0 Formalized the existing and already documented `...$params` parameter
* by adding it to the function signature.
*
- * @global array $wp_registered_widget_updates
+ * @global array $wp_registered_widget_updates The registered widget updates.
*
* @param string $id_base The base ID of a widget created by extending WP_Widget.
* @param callable $update_callback Update callback method for the widget.
@@ -615,7 +625,7 @@
* @since 5.3.0 Formalized the existing and already documented `...$params` parameter
* by adding it to the function signature.
*
- * @global array $wp_registered_widget_controls
+ * @global array $wp_registered_widget_controls The registered widget controls.
*
* @param int|string $id Widget ID.
* @param string $name Name attribute for the widget.
@@ -678,8 +688,8 @@
*
* @since 2.2.0
*
- * @global array $wp_registered_sidebars Registered sidebars.
- * @global array $wp_registered_widgets Registered widgets.
+ * @global array $wp_registered_sidebars The registered sidebars.
+ * @global array $wp_registered_widgets The registered widgets.
*
* @param int|string $index Optional. Index, name or ID of dynamic sidebar. Default 1.
* @return bool True, if widget sidebar was found and called. False if not found or not called.
@@ -889,7 +899,7 @@
*
* @since 2.2.0
*
- * @global array $wp_registered_widgets
+ * @global array $wp_registered_widgets The registered widgets.
*
* @param callable|false $callback Optional. Widget callback to check. Default false.
* @param string|false $widget_id Optional. Widget ID. Optional, but needed for checking.
@@ -908,7 +918,7 @@
if ( is_array( $sidebars_widgets ) ) {
foreach ( $sidebars_widgets as $sidebar => $widgets ) {
- if ( $skip_inactive && ( 'wp_inactive_widgets' === $sidebar || 'orphaned_widgets' === substr( $sidebar, 0, 16 ) ) ) {
+ if ( $skip_inactive && ( 'wp_inactive_widgets' === $sidebar || str_starts_with( $sidebar, 'orphaned_widgets' ) ) ) {
continue;
}
@@ -935,8 +945,8 @@
*
* @since 2.2.0
*
- * @global array $wp_registered_widgets Registered widgets.
- * @global array $wp_registered_sidebars Registered sidebars.
+ * @global array $wp_registered_widgets The registered widgets.
+ * @global array $wp_registered_sidebars The registered sidebars.
*
* @return bool True if using widgets, false otherwise.
*/
@@ -1013,8 +1023,10 @@
global $_wp_sidebars_widgets, $sidebars_widgets;
- // If loading from front page, consult $_wp_sidebars_widgets rather than options
- // to see if wp_convert_widget_settings() has made manipulations in memory.
+ /*
+ * If loading from front page, consult $_wp_sidebars_widgets rather than options
+ * to see if wp_convert_widget_settings() has made manipulations in memory.
+ */
if ( ! is_admin() ) {
if ( empty( $_wp_sidebars_widgets ) ) {
$_wp_sidebars_widgets = get_option( 'sidebars_widgets', array() );
@@ -1096,7 +1108,7 @@
* @since 2.2.0
* @access private
*
- * @global array $wp_registered_sidebars Registered sidebars.
+ * @global array $wp_registered_sidebars The registered sidebars.
*
* @return array
*/
@@ -1302,9 +1314,9 @@
*
* @since 2.8.0
*
- * @global array $wp_registered_sidebars Registered sidebars.
+ * @global array $wp_registered_sidebars The registered sidebars.
* @global array $sidebars_widgets
- * @global array $wp_registered_widgets Registered widgets.
+ * @global array $wp_registered_widgets The registered widgets.
*
* @param string|bool $theme_changed Whether the theme was changed as a boolean. A value
* of 'customize' defers updates for the Customizer.
@@ -1366,6 +1378,8 @@
* @since 4.9.0
* @since 4.9.2 Always tries to restore widget assignments from previous data, not just if sidebars needed mapping.
*
+ * @global array $wp_registered_sidebars The registered sidebars.
+ *
* @param array $existing_sidebars_widgets List of sidebars and their widget instance IDs.
* @return array Mapped sidebars widgets.
*/
@@ -1382,7 +1396,7 @@
}
foreach ( $existing_sidebars_widgets as $sidebar => $widgets ) {
- if ( 'wp_inactive_widgets' === $sidebar || 'orphaned_widgets' === substr( $sidebar, 0, 16 ) ) {
+ if ( 'wp_inactive_widgets' === $sidebar || str_starts_with( $sidebar, 'orphaned_widgets' ) ) {
$new_sidebars_widgets['wp_inactive_widgets'] = array_merge( $new_sidebars_widgets['wp_inactive_widgets'], (array) $widgets );
unset( $existing_sidebars_widgets[ $sidebar ] );
}
@@ -1490,7 +1504,7 @@
// Remove orphaned widgets, we're only interested in previously active sidebars.
foreach ( $old_sidebars_widgets as $sidebar => $widgets ) {
- if ( 'orphaned_widgets' === substr( $sidebar, 0, 16 ) ) {
+ if ( str_starts_with( $sidebar, 'orphaned_widgets' ) ) {
unset( $old_sidebars_widgets[ $sidebar ] );
}
}
@@ -1540,6 +1554,8 @@
*
* @since 4.9.0
*
+ * @global array $wp_registered_widgets The registered widgets.
+ *
* @param array $sidebars_widgets List of sidebars and their widget instance IDs.
* @param array $allowed_widget_ids Optional. List of widget IDs to compare against. Default: Registered widgets.
* @return array Sidebars with allowed widgets.
@@ -1578,7 +1594,7 @@
if ( is_wp_error( $rss ) ) {
if ( is_admin() || current_user_can( 'manage_options' ) ) {
- echo '<p><strong>' . __( 'RSS Error:' ) . '</strong> ' . $rss->get_error_message() . '</p>';
+ echo '<p><strong>' . __( 'RSS Error:' ) . '</strong> ' . esc_html( $rss->get_error_message() ) . '</p>';
}
return;
}
@@ -1627,7 +1643,7 @@
$summary = $desc;
// Change existing [...] to […].
- if ( '[...]' === substr( $summary, -5 ) ) {
+ if ( str_ends_with( $summary, '[...]' ) ) {
$summary = substr( $summary, 0, -5 ) . '[…]';
}
@@ -1701,7 +1717,7 @@
$args['show_date'] = isset( $args['show_date'] ) ? (int) $args['show_date'] : (int) $inputs['show_date'];
if ( ! empty( $args['error'] ) ) {
- echo '<p class="widget-error"><strong>' . __( 'RSS Error:' ) . '</strong> ' . $args['error'] . '</p>';
+ echo '<p class="widget-error"><strong>' . __( 'RSS Error:' ) . '</strong> ' . esc_html( $args['error'] ) . '</p>';
}
$esc_number = esc_attr( $args['number'] );
@@ -1767,7 +1783,7 @@
if ( $items < 1 || 20 < $items ) {
$items = 10;
}
- $url = esc_url_raw( strip_tags( $widget_rss['url'] ) );
+ $url = sanitize_url( strip_tags( $widget_rss['url'] ) );
$title = isset( $widget_rss['title'] ) ? trim( strip_tags( $widget_rss['title'] ) ) : '';
$show_summary = isset( $widget_rss['show_summary'] ) ? (int) $widget_rss['show_summary'] : 0;
$show_author = isset( $widget_rss['show_author'] ) ? (int) $widget_rss['show_author'] : 0;
@@ -1964,6 +1980,9 @@
*
* @since 5.8.0
*
+ * @global array $wp_registered_widgets The registered widgets.
+ * @global array $wp_registered_sidebars The registered sidebars.
+ *
* @param string $widget_id Widget ID.
* @param string $sidebar_id Sidebar ID.
* @return string
@@ -2030,6 +2049,8 @@
*
* @since 5.8.0
*
+ * @global array $wp_registered_widget_controls The registered widget controls.
+ *
* @param string $id Widget ID.
* @return string|null
*/
@@ -2105,3 +2126,29 @@
}
}
}
+
+/**
+ * Registers the previous theme's sidebars for the block themes.
+ *
+ * @since 6.2.0
+ * @access private
+ *
+ * @global array $wp_registered_sidebars The registered sidebars.
+ */
+function _wp_block_theme_register_classic_sidebars() {
+ global $wp_registered_sidebars;
+
+ if ( ! wp_is_block_theme() ) {
+ return;
+ }
+
+ $classic_sidebars = get_theme_mod( 'wp_classic_sidebars' );
+ if ( empty( $classic_sidebars ) ) {
+ return;
+ }
+
+ // Don't use `register_sidebar` since it will enable the `widgets` support for a theme.
+ foreach ( $classic_sidebars as $sidebar ) {
+ $wp_registered_sidebars[ $sidebar['id'] ] = $sidebar;
+ }
+}