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.
Built from https://develop.svn.wordpress.org/trunk@33492


git-svn-id: http://core.svn.wordpress.org/trunk@33459 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dominik Schilling 2015-07-29 18:36:26 +00:00
parent 49b3ad2251
commit 8679a93f16
11 changed files with 82 additions and 158 deletions

View File

@ -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 ),
),

View File

@ -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'] = '<a href="' . $activate_link . '" class="activatelink" title="'
. esc_attr( sprintf( __( 'Activate &#8220;%s&#8221;' ), $title ) ) . '">' . __( 'Activate' ) . '</a>';
$actions['preview'] = '<a href="' . $preview_link . '" class="hide-if-customize" title="'
. esc_attr( sprintf( __( 'Preview &#8220;%s&#8221;' ), $title ) ) . '">' . __( 'Preview' ) . '</a>';
if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
$actions['preview'] .= '<a href="' . wp_customize_url( $stylesheet ) . '" class="load-customize hide-if-no-customize">'
. __( 'Live Preview' ) . '</a>';
@ -205,11 +198,11 @@ class WP_Themes_List_Table extends WP_List_Table {
?>
<a href="<?php echo $preview_link; ?>" class="screenshot hide-if-customize">
<span class="screenshot hide-if-customize">
<?php if ( $screenshot = $theme->get_screenshot() ) : ?>
<img src="<?php echo esc_url( $screenshot ); ?>" alt="" />
<?php endif; ?>
</a>
</span>
<a href="<?php echo wp_customize_url( $stylesheet ); ?>" class="screenshot load-customize hide-if-no-customize">
<?php if ( $screenshot = $theme->get_screenshot() ) : ?>
<img src="<?php echo esc_url( $screenshot ); ?>" alt="" />

View File

@ -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'] = '<a href="' . esc_url( $preview_link ) . '" class="hide-if-customize"><span aria-hidden="true">' . __( 'Preview' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Preview &#8220;%s&#8221;' ), $name ) . '</span></a>';
if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
$install_actions['preview'] .= '<a href="' . wp_customize_url( $stylesheet ) . '" class="hide-if-no-customize load-customize"><span aria-hidden="true">' . __( 'Live Preview' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Live Preview &#8220;%s&#8221;' ), $name ) . '</span></a>';
}
@ -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'] = '<a href="' . wp_customize_url( $stylesheet ) . '" class="hide-if-no-customize load-customize"><span aria-hidden="true">' . __( 'Customize' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Customize &#8220;%s&#8221;' ), $name ) . '</span></a>';
}
} elseif ( current_user_can( 'switch_themes' ) ) {
$update_actions['preview'] = '<a href="' . esc_url( $preview_link ) . '" class="hide-if-customize"><span aria-hidden="true">' . __( 'Preview' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Preview &#8220;%s&#8221;' ), $name ) . '</span></a>';
if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
$update_actions['preview'] .= '<a href="' . wp_customize_url( $stylesheet ) . '" class="hide-if-no-customize load-customize"><span aria-hidden="true">' . __( 'Live Preview' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Live Preview &#8220;%s&#8221;' ), $name ) . '</span></a>';
}

View File

@ -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&amp;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&amp;stylesheet=' . $encoded_slug ), 'delete-theme_' . $slug ) : null,
),
);

View File

@ -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 ),

File diff suppressed because one or more lines are too long

View File

@ -245,7 +245,6 @@ foreach ( $themes as $theme ) :
<a class="button button-secondary activate" href="<?php echo $theme['actions']['activate']; ?>"><?php _e( 'Activate' ); ?></a>
<?php if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { ?>
<a class="button button-primary load-customize hide-if-no-customize" href="<?php echo $theme['actions']['customize']; ?>"><?php _e( 'Live Preview' ); ?></a>
<a class="button button-secondary hide-if-customize" href="<?php echo $theme['actions']['preview']; ?>"><?php _e( 'Preview' ); ?></a>
<?php } ?>
<?php } ?>
@ -347,7 +346,6 @@ $can_delete = current_user_can( 'delete_themes' );
<# } else { #>
<a class="button button-secondary activate" href="{{{ data.actions.activate }}}"><?php _e( 'Activate' ); ?></a>
<a class="button button-primary load-customize hide-if-no-customize" href="{{{ data.actions.customize }}}"><?php _e( 'Live Preview' ); ?></a>
<a class="button button-secondary hide-if-customize" href="{{{ data.actions.preview }}}"><?php _e( 'Preview' ); ?></a>
<# } #>
</div>
@ -409,7 +407,6 @@ $can_delete = current_user_can( 'delete_themes' );
<a href="{{{ data.actions.activate }}}" class="button button-secondary activate"><?php _e( 'Activate' ); ?></a>
<# } #>
<a href="{{{ data.actions.customize }}}" class="button button-primary load-customize hide-if-no-customize"><?php _e( 'Live Preview' ); ?></a>
<a href="{{{ data.actions.preview }}}" class="button button-secondary hide-if-customize"><?php _e( 'Preview' ); ?></a>
</div>
<# if ( ! data.active && data.actions['delete'] ) { #>

View File

@ -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' );

View File

@ -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.
*

View File

@ -660,116 +660,6 @@ function locale_stylesheet() {
echo '<link rel="stylesheet" href="' . $stylesheet . '" type="text/css" media="screen" />';
}
/**
* 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( "|(<a.*?href=([\"']))(.*?)([\"'].*?>)|", '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#i', '', $matches[4]); //Strip out any onclicks from rest of <a>. (?<!\\\) means to ignore the '" if it's escaped by \ to prevent breaking mid-attribute.
if (
( false !== strpos($matches[3], '/wp-admin/') )
||
( false !== strpos( $matches[3], '://' ) && 0 !== strpos( $matches[3], home_url() ) )
||
( false !== strpos($matches[3], '/feed/') )
||
( false !== strpos($matches[3], '/trackback/') )
)
return $matches[1] . "#$matches[2] onclick=$matches[2]return false;" . $matches[4];
$stylesheet = isset( $_GET['stylesheet'] ) ? $_GET['stylesheet'] : '';
$template = isset( $_GET['template'] ) ? $_GET['template'] : '';
$link = add_query_arg( array( 'preview' => 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.
*

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.3-beta4-33491';
$wp_version = '4.3-beta4-33492';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.