From c00346820f0fecb465768c3febeef8ea209583c9 Mon Sep 17 00:00:00 2001 From: azaozz Date: Thu, 8 Sep 2011 20:07:15 +0000 Subject: [PATCH] Make check_theme_switched() run an action so this enhancement is available to plugins and themes too, see #17979 git-svn-id: http://svn.automattic.com/wordpress/trunk@18655 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/default-filters.php | 1 + wp-includes/theme.php | 12 +++++++++++- wp-includes/widgets.php | 19 +++++++++++-------- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index d99df1f64a..1c69f3805f 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -219,6 +219,7 @@ add_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 ); add_action( 'template_redirect', 'wp_shortlink_header', 11, 0 ); add_action( 'wp_print_footer_scripts', '_wp_footer_scripts' ); add_action( 'init', 'check_theme_switched', 99 ); +add_action( 'after_theme_change', '_wp_sidebars_changed' ); if ( isset( $_GET['replytocom'] ) ) add_filter( 'pre_option_blog_public', '__return_zero' ); diff --git a/wp-includes/theme.php b/wp-includes/theme.php index c6d3b3cccd..d30a679925 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -1993,4 +1993,14 @@ function _delete_attachment_theme_mod( $id ) { add_action( 'delete_attachment', '_delete_attachment_theme_mod' ); -?> +/** + * Checks if a theme has been changed and runs 'after_theme_change' hook on the next WP load + * + * @since 3.3 + */ +function check_theme_switched() { + if ( false !== ( $old_theme = get_option( 'theme_switched' ) ) && !empty( $old_theme ) ) { + do_action( 'after_theme_change', $old_theme ); + update_option( 'theme_switched', false ); + } +} diff --git a/wp-includes/widgets.php b/wp-includes/widgets.php index c2ecd5d20a..bc43866fbf 100644 --- a/wp-includes/widgets.php +++ b/wp-includes/widgets.php @@ -1194,16 +1194,19 @@ function _get_widget_id_base($id) { return preg_replace( '/-[0-9]+$/', '', $id ); } -function check_theme_switched() { - if ( false !== ( $old_theme = get_option( 'theme_switched' ) ) && !empty( $old_theme ) ) { - global $sidebars_widgets; +/** + * Handle sidebars config after theme change + * + * @access private + * @since 3.3 + */ +function _wp_sidebars_changed() { + global $sidebars_widgets; - if ( ! is_array( $sidebars_widgets ) ) - $sidebars_widgets = wp_get_sidebars_widgets(); + if ( ! is_array( $sidebars_widgets ) ) + $sidebars_widgets = wp_get_sidebars_widgets(); - retrieve_widgets(); - update_option( 'theme_switched', false ); - } + retrieve_widgets(); } // look for "lost" widgets, this has to run at least on each theme change