From faac72a070781e7305ccaf8ee0da673556562cda Mon Sep 17 00:00:00 2001 From: "Dominik Schilling (ocean90)" Date: Wed, 29 Jul 2015 18:35:40 +0000 Subject: [PATCH] Themes: Remove legacy theme preview. The pre-3.4 theme previewer doesn't work when using a static front page. We kept the old theme preview for no-JS and some browsers that were less capable. But since browsers are doing a better job today we don't need to continue fixing/shipping this legacy code. Bye! fixes #33178. git-svn-id: https://develop.svn.wordpress.org/trunk@33492 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/customize.php | 9 -- .../includes/class-wp-themes-list-table.php | 11 +- .../includes/class-wp-upgrader-skins.php | 15 +-- src/wp-admin/includes/theme.php | 7 -- src/wp-admin/js/customize-controls.js | 7 +- src/wp-admin/themes.php | 3 - src/wp-includes/default-filters.php | 1 - src/wp-includes/deprecated.php | 73 ++++++++++++ src/wp-includes/theme.php | 110 ------------------ 9 files changed, 80 insertions(+), 156 deletions(-) diff --git a/src/wp-admin/customize.php b/src/wp-admin/customize.php index 6871fdb552..4f176781fc 100644 --- a/src/wp-admin/customize.php +++ b/src/wp-admin/customize.php @@ -213,14 +213,6 @@ do_action( 'customize_controls_print_scripts' ); */ $allowed_urls = array_unique( apply_filters( 'customize_allowed_urls', $allowed_urls ) ); - $fallback_url = add_query_arg( array( - 'preview' => 1, - 'template' => $wp_customize->get_template(), - 'stylesheet' => $wp_customize->get_stylesheet(), - 'preview_iframe' => true, - 'TB_iframe' => 'true' - ), home_url( '/' ) ); - $login_url = add_query_arg( array( 'interim-login' => 1, 'customize-login' => 1 @@ -239,7 +231,6 @@ do_action( 'customize_controls_print_scripts' ); 'ajax' => esc_url_raw( admin_url( 'admin-ajax.php', 'relative' ) ), 'allowed' => array_map( 'esc_url_raw', $allowed_urls ), 'isCrossDomain' => $cross_domain, - 'fallback' => esc_url_raw( $fallback_url ), 'home' => esc_url_raw( home_url( '/' ) ), 'login' => esc_url_raw( $login_url ), ), diff --git a/src/wp-admin/includes/class-wp-themes-list-table.php b/src/wp-admin/includes/class-wp-themes-list-table.php index 0d804aeb54..e01e3d4636 100644 --- a/src/wp-admin/includes/class-wp-themes-list-table.php +++ b/src/wp-admin/includes/class-wp-themes-list-table.php @@ -174,17 +174,10 @@ class WP_Themes_List_Table extends WP_List_Table { $activate_link = wp_nonce_url( "themes.php?action=activate&template=" . urlencode( $template ) . "&stylesheet=" . urlencode( $stylesheet ), 'switch-theme_' . $stylesheet ); - $preview_link = esc_url( add_query_arg( - array( 'preview' => 1, 'template' => urlencode( $template ), 'stylesheet' => urlencode( $stylesheet ), 'preview_iframe' => true, 'TB_iframe' => 'true' ), - home_url( '/' ) ) ); - $actions = array(); $actions['activate'] = '' . __( 'Activate' ) . ''; - $actions['preview'] = '' . __( 'Preview' ) . ''; - if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { $actions['preview'] .= '' . __( 'Live Preview' ) . ''; @@ -205,11 +198,11 @@ class WP_Themes_List_Table extends WP_List_Table { ?> - + get_screenshot() ) : ?> - + get_screenshot() ) : ?> diff --git a/src/wp-admin/includes/class-wp-upgrader-skins.php b/src/wp-admin/includes/class-wp-upgrader-skins.php index b0cd3c15ad..4f4ea063c0 100644 --- a/src/wp-admin/includes/class-wp-upgrader-skins.php +++ b/src/wp-admin/includes/class-wp-upgrader-skins.php @@ -650,12 +650,6 @@ class Theme_Installer_Skin extends WP_Upgrader_Skin { $stylesheet = $this->upgrader->result['destination_name']; $template = $theme_info->get_template(); - $preview_link = add_query_arg( array( - 'preview' => 1, - 'template' => urlencode( $template ), - 'stylesheet' => urlencode( $stylesheet ), - ), trailingslashit( home_url() ) ); - $activate_link = add_query_arg( array( 'action' => 'activate', 'template' => urlencode( $template ), @@ -664,7 +658,7 @@ class Theme_Installer_Skin extends WP_Upgrader_Skin { $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet ); $install_actions = array(); - $install_actions['preview'] = '' . sprintf( __( 'Preview “%s”' ), $name ) . ''; + if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { $install_actions['preview'] .= '' . sprintf( __( 'Live Preview “%s”' ), $name ) . ''; } @@ -732,12 +726,6 @@ class Theme_Upgrader_Skin extends WP_Upgrader_Skin { $stylesheet = $this->upgrader->result['destination_name']; $template = $theme_info->get_template(); - $preview_link = add_query_arg( array( - 'preview' => 1, - 'template' => urlencode( $template ), - 'stylesheet' => urlencode( $stylesheet ), - ), trailingslashit( home_url() ) ); - $activate_link = add_query_arg( array( 'action' => 'activate', 'template' => urlencode( $template ), @@ -750,7 +738,6 @@ class Theme_Upgrader_Skin extends WP_Upgrader_Skin { $update_actions['preview'] = '' . sprintf( __( 'Customize “%s”' ), $name ) . ''; } } elseif ( current_user_can( 'switch_themes' ) ) { - $update_actions['preview'] = '' . sprintf( __( 'Preview “%s”' ), $name ) . ''; if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { $update_actions['preview'] .= '' . sprintf( __( 'Live Preview “%s”' ), $name ) . ''; } diff --git a/src/wp-admin/includes/theme.php b/src/wp-admin/includes/theme.php index 80a14b6114..9bbfc7215d 100644 --- a/src/wp-admin/includes/theme.php +++ b/src/wp-admin/includes/theme.php @@ -479,13 +479,6 @@ function wp_prepare_themes_for_js( $themes = null ) { 'actions' => array( 'activate' => current_user_can( 'switch_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=activate&stylesheet=' . $encoded_slug ), 'switch-theme_' . $slug ) : null, 'customize' => ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) ? wp_customize_url( $slug ) : null, - 'preview' => add_query_arg( array( - 'preview' => 1, - 'template' => urlencode( $theme->get_template() ), - 'stylesheet' => urlencode( $slug ), - 'preview_iframe' => true, - 'TB_iframe' => true, - ), home_url( '/' ) ), 'delete' => current_user_can( 'delete_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=delete&stylesheet=' . $encoded_slug ), 'delete-theme_' . $slug ) : null, ), ); diff --git a/src/wp-admin/js/customize-controls.js b/src/wp-admin/js/customize-controls.js index ff93d5fa49..739b96233b 100644 --- a/src/wp-admin/js/customize-controls.js +++ b/src/wp-admin/js/customize-controls.js @@ -3036,9 +3036,10 @@ return; } - // Redirect to the fallback preview if any incompatibilities are found. - if ( ! $.support.postMessage || ( ! $.support.cors && api.settings.isCrossDomain ) ) - return window.location = api.settings.url.fallback; + // Bail if any incompatibilities are found. + if ( ! $.support.postMessage || ( ! $.support.cors && api.settings.isCrossDomain ) ) { + return; + } var parent, topFocus, body = $( document.body ), diff --git a/src/wp-admin/themes.php b/src/wp-admin/themes.php index 3e88d12ec0..5c007df79f 100644 --- a/src/wp-admin/themes.php +++ b/src/wp-admin/themes.php @@ -245,7 +245,6 @@ foreach ( $themes as $theme ) : - @@ -347,7 +346,6 @@ $can_delete = current_user_can( 'delete_themes' ); <# } else { #> - <# } #> @@ -409,7 +407,6 @@ $can_delete = current_user_can( 'delete_themes' ); <# } #> - <# if ( ! data.active && data.actions['delete'] ) { #> diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index 07f449f2f3..27b0aa784a 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -335,7 +335,6 @@ add_action( 'split_shared_term', '_wp_check_split_terms_in_menus', 10, 4 ); * Filters formerly mixed into wp-includes */ // Theme -add_action( 'setup_theme', 'preview_theme' ); add_action( 'wp_loaded', '_custom_header_background_just_in_time' ); add_action( 'plugins_loaded', '_wp_customize_include' ); add_action( 'admin_enqueue_scripts', '_wp_customize_loader_settings' ); diff --git a/src/wp-includes/deprecated.php b/src/wp-includes/deprecated.php index f5bc679c6a..ac3910550d 100644 --- a/src/wp-includes/deprecated.php +++ b/src/wp-includes/deprecated.php @@ -3492,6 +3492,79 @@ function url_is_accessable_via_ssl( $url ) { return false; } +/** + * Start preview theme output buffer. + * + * Will only perform task if the user has permissions and template and preview + * query variables exist. + * + * @since 2.6.0 + * @deprecated 4.3.0 + */ +function preview_theme() { + _deprecated_function( __FUNCTION__, '4.3' ); +} + +/** + * Private function to modify the current template when previewing a theme + * + * @since 2.9.0 + * @deprecated 4.3.0 + * @access private + * + * @return string + */ +function _preview_theme_template_filter() { + _deprecated_function( __FUNCTION__, '4.3' ); + return ''; +} + +/** + * Private function to modify the current stylesheet when previewing a theme + * + * @since 2.9.0 + * @deprecated 4.3.0 + * @access private + * + * @return string + */ +function _preview_theme_stylesheet_filter() { + _deprecated_function( __FUNCTION__, '4.3' ); + return ''; +} + +/** + * Callback function for ob_start() to capture all links in the theme. + * + * @since 2.6.0 + * @deprecated 4.3.0 + * @access private + * + * @param string $content + * @return string + */ +function preview_theme_ob_filter( $content ) { + _deprecated_function( __FUNCTION__, '4.3' ); + return $content; +} + +/** + * Manipulates preview theme links in order to control and maintain location. + * + * Callback function for preg_replace_callback() to accept and filter matches. + * + * @since 2.6.0 + * @deprecated 4.3.0 + * @access private + * + * @param array $matches + * @return string + */ +function preview_theme_ob_filter_callback( $matches ) { + _deprecated_function( __FUNCTION__, '4.3' ); + return ''; +} + /** * Formats text for the rich text editor. * diff --git a/src/wp-includes/theme.php b/src/wp-includes/theme.php index d35a337ebf..823d2ca471 100644 --- a/src/wp-includes/theme.php +++ b/src/wp-includes/theme.php @@ -660,116 +660,6 @@ function locale_stylesheet() { echo ''; } -/** - * Start preview theme output buffer. - * - * Will only perform task if the user has permissions and template and preview - * query variables exist. - * - * @since 2.6.0 - */ -function preview_theme() { - if ( ! (isset($_GET['template']) && isset($_GET['preview'])) ) - return; - - if ( !current_user_can( 'switch_themes' ) ) - return; - - // Admin Thickbox requests - if ( isset( $_GET['preview_iframe'] ) ) - show_admin_bar( false ); - - $_GET['template'] = preg_replace('|[^a-z0-9_./-]|i', '', $_GET['template']); - - if ( validate_file($_GET['template']) ) - return; - - add_filter( 'template', '_preview_theme_template_filter' ); - - if ( isset($_GET['stylesheet']) ) { - $_GET['stylesheet'] = preg_replace('|[^a-z0-9_./-]|i', '', $_GET['stylesheet']); - if ( validate_file($_GET['stylesheet']) ) - return; - add_filter( 'stylesheet', '_preview_theme_stylesheet_filter' ); - } - - // Prevent theme mods to current theme being used on theme being previewed - add_filter( 'pre_option_theme_mods_' . get_option( 'stylesheet' ), '__return_empty_array' ); - - ob_start( 'preview_theme_ob_filter' ); -} - -/** - * Private function to modify the current template when previewing a theme - * - * @since 2.9.0 - * @access private - * - * @return string - */ -function _preview_theme_template_filter() { - return isset($_GET['template']) ? $_GET['template'] : ''; -} - -/** - * Private function to modify the current stylesheet when previewing a theme - * - * @since 2.9.0 - * @access private - * - * @return string - */ -function _preview_theme_stylesheet_filter() { - return isset($_GET['stylesheet']) ? $_GET['stylesheet'] : ''; -} - -/** - * Callback function for ob_start() to capture all links in the theme. - * - * @since 2.6.0 - * @access private - * - * @param string $content - * @return string - */ -function preview_theme_ob_filter( $content ) { - return preg_replace_callback( "|()|", 'preview_theme_ob_filter_callback', $content ); -} - -/** - * Manipulates preview theme links in order to control and maintain location. - * - * Callback function for preg_replace_callback() to accept and filter matches. - * - * @since 2.6.0 - * @access private - * - * @param array $matches - * @return string - */ -function preview_theme_ob_filter_callback( $matches ) { - if ( strpos($matches[4], 'onclick') !== false ) - $matches[4] = preg_replace('#onclick=([\'"]).*?(?. (? 1, 'template' => $template, 'stylesheet' => $stylesheet, 'preview_iframe' => 1 ), $matches[3] ); - if ( 0 === strpos($link, 'preview=1') ) - $link = "?$link"; - return $matches[1] . esc_attr( $link ) . $matches[4]; -} - /** * Switches the theme. *