Make WordPress Core


Ignore:
Timestamp:
07/29/2015 06:35:40 PM (9 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.