Changeset 33492 for trunk/src/wp-includes/theme.php
- Timestamp:
- 07/29/2015 06:35:40 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/theme.php
r33278 r33492 662 662 663 663 /** 664 * Start preview theme output buffer.665 *666 * Will only perform task if the user has permissions and template and preview667 * query variables exist.668 *669 * @since 2.6.0670 */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 requests679 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 previewed697 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 theme704 *705 * @since 2.9.0706 * @access private707 *708 * @return string709 */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 theme716 *717 * @since 2.9.0718 * @access private719 *720 * @return string721 */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.0730 * @access private731 *732 * @param string $content733 * @return string734 */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.0745 * @access private746 *747 * @param array $matches748 * @return string749 */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 /**774 664 * Switches the theme. 775 665 *
Note: See TracChangeset
for help on using the changeset viewer.