WordPress.org

Make WordPress Core

Changeset 33492


Ignore:
Timestamp:
07/29/15 18:35:40 (3 years ago)
Author:
ocean90
Message:

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.

Location:
trunk/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/customize.php

    r33153 r33492  
    214214    $allowed_urls = array_unique( apply_filters( 'customize_allowed_urls', $allowed_urls ) ); 
    215215 
    216     $fallback_url = add_query_arg( array( 
    217         'preview'        => 1, 
    218         'template'       => $wp_customize->get_template(), 
    219         'stylesheet'     => $wp_customize->get_stylesheet(), 
    220         'preview_iframe' => true, 
    221         'TB_iframe'      => 'true' 
    222     ), home_url( '/' ) ); 
    223  
    224216    $login_url = add_query_arg( array( 
    225217        'interim-login' => 1, 
     
    240232            'allowed'       => array_map( 'esc_url_raw', $allowed_urls ), 
    241233            'isCrossDomain' => $cross_domain, 
    242             'fallback'      => esc_url_raw( $fallback_url ), 
    243234            'home'          => esc_url_raw( home_url( '/' ) ), 
    244235            'login'         => esc_url_raw( $login_url ), 
  • trunk/src/wp-admin/includes/class-wp-themes-list-table.php

    r32656 r33492  
    175175            $activate_link = wp_nonce_url( "themes.php?action=activate&template=" . urlencode( $template ) . "&stylesheet=" . urlencode( $stylesheet ), 'switch-theme_' . $stylesheet ); 
    176176 
    177             $preview_link = esc_url( add_query_arg( 
    178                 array( 'preview' => 1, 'template' => urlencode( $template ), 'stylesheet' => urlencode( $stylesheet ), 'preview_iframe' => true, 'TB_iframe' => 'true' ), 
    179                 home_url( '/' ) ) ); 
    180  
    181177            $actions = array(); 
    182178            $actions['activate'] = '<a href="' . $activate_link . '" class="activatelink" title="' 
    183179                . esc_attr( sprintf( __( 'Activate &#8220;%s&#8221;' ), $title ) ) . '">' . __( 'Activate' ) . '</a>'; 
    184  
    185             $actions['preview'] = '<a href="' . $preview_link . '" class="hide-if-customize" title="' 
    186                 . esc_attr( sprintf( __( 'Preview &#8220;%s&#8221;' ), $title ) ) . '">' . __( 'Preview' ) . '</a>'; 
    187180 
    188181            if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { 
     
    206199            ?> 
    207200 
    208             <a href="<?php echo $preview_link; ?>" class="screenshot hide-if-customize"> 
     201            <span class="screenshot hide-if-customize"> 
    209202                <?php if ( $screenshot = $theme->get_screenshot() ) : ?> 
    210203                    <img src="<?php echo esc_url( $screenshot ); ?>" alt="" /> 
    211204                <?php endif; ?> 
    212             </a> 
     205            </span> 
    213206            <a href="<?php echo wp_customize_url( $stylesheet ); ?>" class="screenshot load-customize hide-if-no-customize"> 
    214207                <?php if ( $screenshot = $theme->get_screenshot() ) : ?> 
  • trunk/src/wp-admin/includes/class-wp-upgrader-skins.php

    r32974 r33492  
    651651        $template   = $theme_info->get_template(); 
    652652 
    653         $preview_link = add_query_arg( array( 
    654             'preview'    => 1, 
    655             'template'   => urlencode( $template ), 
    656             'stylesheet' => urlencode( $stylesheet ), 
    657         ), trailingslashit( home_url() ) ); 
    658  
    659653        $activate_link = add_query_arg( array( 
    660654            'action'     => 'activate', 
     
    665659 
    666660        $install_actions = array(); 
    667         $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>'; 
     661 
    668662        if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { 
    669663            $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>'; 
     
    733727            $template   = $theme_info->get_template(); 
    734728 
    735             $preview_link = add_query_arg( array( 
    736                 'preview'    => 1, 
    737                 'template'   => urlencode( $template ), 
    738                 'stylesheet' => urlencode( $stylesheet ), 
    739             ), trailingslashit( home_url() ) ); 
    740  
    741729            $activate_link = add_query_arg( array( 
    742730                'action'     => 'activate', 
     
    751739                } 
    752740            } elseif ( current_user_can( 'switch_themes' ) ) { 
    753                 $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>'; 
    754741                if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { 
    755742                    $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>'; 
  • trunk/src/wp-admin/includes/theme.php

    r32965 r33492  
    480480                'activate' => current_user_can( 'switch_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=activate&amp;stylesheet=' . $encoded_slug ), 'switch-theme_' . $slug ) : null, 
    481481                'customize' => ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) ? wp_customize_url( $slug ) : null, 
    482                 'preview'   => add_query_arg( array( 
    483                     'preview'        => 1, 
    484                     'template'       => urlencode( $theme->get_template() ), 
    485                     'stylesheet'     => urlencode( $slug ), 
    486                     'preview_iframe' => true, 
    487                     'TB_iframe'      => true, 
    488                 ), home_url( '/' ) ), 
    489482                'delete'   => current_user_can( 'delete_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=delete&amp;stylesheet=' . $encoded_slug ), 'delete-theme_' . $slug ) : null, 
    490483            ), 
  • trunk/src/wp-admin/js/customize-controls.js

    r33454 r33492  
    30373037        } 
    30383038 
    3039         // Redirect to the fallback preview if any incompatibilities are found. 
    3040         if ( ! $.support.postMessage || ( ! $.support.cors && api.settings.isCrossDomain ) ) 
    3041             return window.location = api.settings.url.fallback; 
     3039        // Bail if any incompatibilities are found. 
     3040        if ( ! $.support.postMessage || ( ! $.support.cors && api.settings.isCrossDomain ) ) { 
     3041            return; 
     3042        } 
    30423043 
    30433044        var parent, topFocus, 
  • trunk/src/wp-admin/themes.php

    r33456 r33492  
    246246        <?php if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { ?> 
    247247            <a class="button button-primary load-customize hide-if-no-customize" href="<?php echo $theme['actions']['customize']; ?>"><?php _e( 'Live Preview' ); ?></a> 
    248             <a class="button button-secondary hide-if-customize" href="<?php echo $theme['actions']['preview']; ?>"><?php _e( 'Preview' ); ?></a> 
    249248        <?php } ?> 
    250249    <?php } ?> 
     
    348347        <a class="button button-secondary activate" href="{{{ data.actions.activate }}}"><?php _e( 'Activate' ); ?></a> 
    349348        <a class="button button-primary load-customize hide-if-no-customize" href="{{{ data.actions.customize }}}"><?php _e( 'Live Preview' ); ?></a> 
    350         <a class="button button-secondary hide-if-customize" href="{{{ data.actions.preview }}}"><?php _e( 'Preview' ); ?></a> 
    351349    <# } #> 
    352350 
     
    410408                <# } #> 
    411409                <a href="{{{ data.actions.customize }}}" class="button button-primary load-customize hide-if-no-customize"><?php _e( 'Live Preview' ); ?></a> 
    412                 <a href="{{{ data.actions.preview }}}" class="button button-secondary hide-if-customize"><?php _e( 'Preview' ); ?></a> 
    413410            </div> 
    414411 
  • trunk/src/wp-includes/default-filters.php

    r33187 r33492  
    336336 */ 
    337337// Theme 
    338 add_action( 'setup_theme', 'preview_theme' ); 
    339338add_action( 'wp_loaded', '_custom_header_background_just_in_time' ); 
    340339add_action( 'plugins_loaded', '_wp_customize_include' ); 
  • trunk/src/wp-includes/deprecated.php

    r32964 r33492  
    34943494 
    34953495/** 
     3496 * Start preview theme output buffer. 
     3497 * 
     3498 * Will only perform task if the user has permissions and template and preview 
     3499 * query variables exist. 
     3500 * 
     3501 * @since 2.6.0 
     3502 * @deprecated 4.3.0 
     3503 */ 
     3504function preview_theme() { 
     3505    _deprecated_function( __FUNCTION__, '4.3' ); 
     3506} 
     3507 
     3508/** 
     3509 * Private function to modify the current template when previewing a theme 
     3510 * 
     3511 * @since 2.9.0 
     3512 * @deprecated 4.3.0 
     3513 * @access private 
     3514 * 
     3515 * @return string 
     3516 */ 
     3517function _preview_theme_template_filter() { 
     3518    _deprecated_function( __FUNCTION__, '4.3' ); 
     3519    return ''; 
     3520} 
     3521 
     3522/** 
     3523 * Private function to modify the current stylesheet when previewing a theme 
     3524 * 
     3525 * @since 2.9.0 
     3526 * @deprecated 4.3.0 
     3527 * @access private 
     3528 * 
     3529 * @return string 
     3530 */ 
     3531function _preview_theme_stylesheet_filter() { 
     3532    _deprecated_function( __FUNCTION__, '4.3' ); 
     3533    return ''; 
     3534} 
     3535 
     3536/** 
     3537 * Callback function for ob_start() to capture all links in the theme. 
     3538 * 
     3539 * @since 2.6.0 
     3540 * @deprecated 4.3.0 
     3541 * @access private 
     3542 * 
     3543 * @param string $content 
     3544 * @return string 
     3545 */ 
     3546function preview_theme_ob_filter( $content ) { 
     3547    _deprecated_function( __FUNCTION__, '4.3' ); 
     3548    return $content; 
     3549} 
     3550 
     3551/** 
     3552 * Manipulates preview theme links in order to control and maintain location. 
     3553 * 
     3554 * Callback function for preg_replace_callback() to accept and filter matches. 
     3555 * 
     3556 * @since 2.6.0 
     3557 * @deprecated 4.3.0 
     3558 * @access private 
     3559 * 
     3560 * @param array $matches 
     3561 * @return string 
     3562 */ 
     3563function preview_theme_ob_filter_callback( $matches ) { 
     3564    _deprecated_function( __FUNCTION__, '4.3' ); 
     3565    return ''; 
     3566} 
     3567 
     3568/** 
    34963569 * Formats text for the rich text editor. 
    34973570 * 
  • trunk/src/wp-includes/theme.php

    r33278 r33492  
    662662 
    663663/** 
    664  * Start preview theme output buffer. 
    665  * 
    666  * Will only perform task if the user has permissions and template and preview 
    667  * query variables exist. 
    668  * 
    669  * @since 2.6.0 
    670  */ 
    671 function preview_theme() { 
    672     if ( ! (isset($_GET['template']) && isset($_GET['preview'])) ) 
    673         return; 
    674  
    675     if ( !current_user_can( 'switch_themes' ) ) 
    676         return; 
    677  
    678     // Admin Thickbox requests 
    679     if ( isset( $_GET['preview_iframe'] ) ) 
    680         show_admin_bar( false ); 
    681  
    682     $_GET['template'] = preg_replace('|[^a-z0-9_./-]|i', '', $_GET['template']); 
    683  
    684     if ( validate_file($_GET['template']) ) 
    685         return; 
    686  
    687     add_filter( 'template', '_preview_theme_template_filter' ); 
    688  
    689     if ( isset($_GET['stylesheet']) ) { 
    690         $_GET['stylesheet'] = preg_replace('|[^a-z0-9_./-]|i', '', $_GET['stylesheet']); 
    691         if ( validate_file($_GET['stylesheet']) ) 
    692             return; 
    693         add_filter( 'stylesheet', '_preview_theme_stylesheet_filter' ); 
    694     } 
    695  
    696     // Prevent theme mods to current theme being used on theme being previewed 
    697     add_filter( 'pre_option_theme_mods_' . get_option( 'stylesheet' ), '__return_empty_array' ); 
    698  
    699     ob_start( 'preview_theme_ob_filter' ); 
    700 } 
    701  
    702 /** 
    703  * Private function to modify the current template when previewing a theme 
    704  * 
    705  * @since 2.9.0 
    706  * @access private 
    707  * 
    708  * @return string 
    709  */ 
    710 function _preview_theme_template_filter() { 
    711     return isset($_GET['template']) ? $_GET['template'] : ''; 
    712 } 
    713  
    714 /** 
    715  * Private function to modify the current stylesheet when previewing a theme 
    716  * 
    717  * @since 2.9.0 
    718  * @access private 
    719  * 
    720  * @return string 
    721  */ 
    722 function _preview_theme_stylesheet_filter() { 
    723     return isset($_GET['stylesheet']) ? $_GET['stylesheet'] : ''; 
    724 } 
    725  
    726 /** 
    727  * Callback function for ob_start() to capture all links in the theme. 
    728  * 
    729  * @since 2.6.0 
    730  * @access private 
    731  * 
    732  * @param string $content 
    733  * @return string 
    734  */ 
    735 function preview_theme_ob_filter( $content ) { 
    736     return preg_replace_callback( "|(<a.*?href=([\"']))(.*?)([\"'].*?>)|", 'preview_theme_ob_filter_callback', $content ); 
    737 } 
    738  
    739 /** 
    740  * Manipulates preview theme links in order to control and maintain location. 
    741  * 
    742  * Callback function for preg_replace_callback() to accept and filter matches. 
    743  * 
    744  * @since 2.6.0 
    745  * @access private 
    746  * 
    747  * @param array $matches 
    748  * @return string 
    749  */ 
    750 function preview_theme_ob_filter_callback( $matches ) { 
    751     if ( strpos($matches[4], 'onclick') !== false ) 
    752         $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. 
    753     if ( 
    754         ( false !== strpos($matches[3], '/wp-admin/') ) 
    755     || 
    756         ( false !== strpos( $matches[3], '://' ) && 0 !== strpos( $matches[3], home_url() ) ) 
    757     || 
    758         ( false !== strpos($matches[3], '/feed/') ) 
    759     || 
    760         ( false !== strpos($matches[3], '/trackback/') ) 
    761     ) 
    762         return $matches[1] . "#$matches[2] onclick=$matches[2]return false;" . $matches[4]; 
    763  
    764     $stylesheet = isset( $_GET['stylesheet'] ) ? $_GET['stylesheet'] : ''; 
    765     $template   = isset( $_GET['template'] )   ? $_GET['template']   : ''; 
    766  
    767     $link = add_query_arg( array( 'preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'preview_iframe' => 1 ), $matches[3] ); 
    768     if ( 0 === strpos($link, 'preview=1') ) 
    769         $link = "?$link"; 
    770     return $matches[1] . esc_attr( $link ) . $matches[4]; 
    771 } 
    772  
    773 /** 
    774664 * Switches the theme. 
    775665 * 
Note: See TracChangeset for help on using the changeset viewer.