Make WordPress Core

Ticket #20921: 20921.3.diff

File 20921.3.diff, 9.6 KB (added by nacin, 13 years ago)
  • wp-includes/class-wp-customize-manager.php

     
    7272         *
    7373         * @since 3.4.0
    7474         */
    75         private function wp_die( $ajax_message, $message ) {
     75        protected function wp_die( $ajax_message, $message = null ) {
    7676                if ( $this->doing_ajax() )
    7777                        wp_die( $ajax_message );
    7878
     79                if ( ! $message )
     80                        $message = __( 'Cheatin’ uh?' );
     81
    7982                wp_die( $message );
    8083        }
    8184
     
    100103        public function setup_theme() {
    101104                if ( is_admin() && ! $this->doing_ajax() )
    102105                    auth_redirect();
    103                 elseif ( $this->doing_ajax() && ! is_user_logged_in())
    104                     wp_die( 0 );
     106                elseif ( $this->doing_ajax() && ! is_user_logged_in() )
     107                    $this->wp_die( 0 );
    105108
     109                if ( ! current_user_can( 'edit_theme_options' ) )
     110                        $this->wp_die( -1 );
     111
    106112                send_origin_headers();
     113                show_admin_bar( false );
    107114
    108115                $this->original_stylesheet = get_stylesheet();
    109116
    110117                $this->theme = wp_get_theme( isset( $_REQUEST['theme'] ) ? $_REQUEST['theme'] : null );
    111118
    112                 // You can't preview a theme if it doesn't exist, or if it is not allowed (unless active).
    113                 if ( ! $this->theme->exists() )
    114                         $this->wp_die( -1, __( 'Cheatin’ uh?' ) );
     119                if ( $this->is_theme_active() ) {
     120                        // Once the theme is loaded, we'll validate it.
     121                        add_action( 'after_setup_theme', array( $this, 'after_setup_theme' ) );
     122                } else {
     123                        if ( ! current_user_can( 'switch_themes' ) )
     124                                $this->wp_die( -1 );
    115125
    116                 if ( $this->theme->get_stylesheet() != get_stylesheet() && ( ! $this->theme()->is_allowed() || ! current_user_can( 'switch_themes' ) ) )
    117                         $this->wp_die( -1, __( 'Cheatin’ uh?' ) );
     126                        // If the theme isn't active, you can't preview it if it is not allowed or has errors.
     127                        if ( $this->theme()->errors() )
     128                                $this->wp_die( -1 );
    118129
    119                 if ( ! current_user_can( 'edit_theme_options' ) )
    120                         $this->wp_die( -1, __( 'Cheatin’ uh?' ) );
     130                        if ( ! $this->theme()->is_allowed() )
     131                                $this->wp_die( -1 );
     132                }
    121133
    122134                $this->start_previewing_theme();
    123                 show_admin_bar( false );
    124135        }
    125136
     137        function after_setup_theme() {
     138                if ( ! $this->doing_ajax() && ! validate_current_theme() ) {
     139                        wp_redirect( 'themes.php?broken=true' );
     140                        exit;
     141                }
     142        }
     143
    126144        /**
    127145         * Start previewing the selected theme.
    128146         *
     
    137155
    138156                $this->previewing = true;
    139157
    140                 add_filter( 'template', array( $this, 'get_template' ) );
    141                 add_filter( 'stylesheet', array( $this, 'get_stylesheet' ) );
    142                 add_filter( 'pre_option_current_theme', array( $this, 'current_theme' ) );
     158                if ( ! $this->is_theme_active() ) {
     159                        add_filter( 'template', array( $this, 'get_template' ) );
     160                        add_filter( 'stylesheet', array( $this, 'get_stylesheet' ) );
     161                        add_filter( 'pre_option_current_theme', array( $this, 'current_theme' ) );
     162       
     163                        // @link: http://core.trac.wordpress.org/ticket/20027
     164                        add_filter( 'pre_option_stylesheet', array( $this, 'get_stylesheet' ) );
     165                        add_filter( 'pre_option_template', array( $this, 'get_template' ) );
     166       
     167                        // Handle custom theme roots.
     168                        add_filter( 'pre_option_stylesheet_root', array( $this, 'get_stylesheet_root' ) );
     169                        add_filter( 'pre_option_template_root', array( $this, 'get_template_root' ) );
     170                }
    143171
    144                 // @link: http://core.trac.wordpress.org/ticket/20027
    145                 add_filter( 'pre_option_stylesheet', array( $this, 'get_stylesheet' ) );
    146                 add_filter( 'pre_option_template', array( $this, 'get_template' ) );
    147 
    148                 // Handle custom theme roots.
    149                 add_filter( 'pre_option_stylesheet_root', array( $this, 'get_stylesheet_root' ) );
    150                 add_filter( 'pre_option_template_root', array( $this, 'get_template_root' ) );
    151 
    152172                do_action( 'start_previewing_theme', $this );
    153173        }
    154174
     
    165185
    166186                $this->previewing = false;
    167187
    168                 remove_filter( 'template', array( $this, 'get_template' ) );
    169                 remove_filter( 'stylesheet', array( $this, 'get_stylesheet' ) );
    170                 remove_filter( 'pre_option_current_theme', array( $this, 'current_theme' ) );
     188                if ( ! $this->is_theme_active() ) {
     189                        remove_filter( 'template', array( $this, 'get_template' ) );
     190                        remove_filter( 'stylesheet', array( $this, 'get_stylesheet' ) );
     191                        remove_filter( 'pre_option_current_theme', array( $this, 'current_theme' ) );
     192       
     193                        // @link: http://core.trac.wordpress.org/ticket/20027
     194                        remove_filter( 'pre_option_stylesheet', array( $this, 'get_stylesheet' ) );
     195                        remove_filter( 'pre_option_template', array( $this, 'get_template' ) );
     196       
     197                        // Handle custom theme roots.
     198                        remove_filter( 'pre_option_stylesheet_root', array( $this, 'get_stylesheet_root' ) );
     199                        remove_filter( 'pre_option_template_root', array( $this, 'get_template_root' ) );
     200                }
    171201
    172                 // @link: http://core.trac.wordpress.org/ticket/20027
    173                 remove_filter( 'pre_option_stylesheet', array( $this, 'get_stylesheet' ) );
    174                 remove_filter( 'pre_option_template', array( $this, 'get_template' ) );
    175 
    176                 // Handle custom theme roots.
    177                 remove_filter( 'pre_option_stylesheet_root', array( $this, 'get_stylesheet_root' ) );
    178                 remove_filter( 'pre_option_template_root', array( $this, 'get_template_root' ) );
    179 
    180202                do_action( 'stop_previewing_theme', $this );
    181203        }
    182204
     
    389411         * @return string Template name.
    390412         */
    391413        public function get_template() {
    392                 return $this->theme->get_template();
     414                return $this->theme()->get_template();
    393415        }
    394416
    395417        /**
     
    400422         * @return string Stylesheet name.
    401423         */
    402424        public function get_stylesheet() {
    403                 return $this->theme->get_stylesheet();
     425                return $this->theme()->get_stylesheet();
    404426        }
    405427
    406428        /**
     
    433455         * @return string Theme name.
    434456         */
    435457        public function current_theme( $current_theme ) {
    436                 return $this->theme->display('Name');
     458                return $this->theme()->display('Name');
    437459        }
    438460
    439461        /**
     
    448470                check_ajax_referer( 'customize_controls-' . $this->get_stylesheet(), 'nonce' );
    449471
    450472                // Do we have to switch themes?
    451                 if ( $this->get_stylesheet() != $this->original_stylesheet ) {
     473                if ( ! $this->is_theme_active() ) {
    452474                        // Temporarily stop previewing the theme to allow switch_themes()
    453475                        // to operate properly.
    454476                        $this->stop_previewing_theme();
     
    462484                        $setting->save();
    463485                }
    464486
    465                 add_action( 'admin_notices', array( $this, '_save_feedback' ) );
    466 
    467487                die;
    468488        }
    469489
    470490        /**
    471          * Show an admin notice after settings are saved.
    472          *
    473          * @since 3.4.0
    474          */
    475         public function _save_feedback() {
    476                 ?>
    477                 <div class="updated"><p><?php printf( __( 'Settings saved and theme activated. <a href="%s">Visit site</a>.' ), home_url( '/' ) ); ?></p></div>
    478                 <?php
    479         }
    480 
    481         /**
    482491         * Add a customize setting.
    483492         *
    484493         * @since 3.4.0
  • wp-admin/customize.php

     
    161161                'url'      => array(
    162162                        'preview'       => esc_url( $url ? $url : home_url( '/' ) ),
    163163                        'parent'        => esc_url( admin_url() ),
    164                         'activated'     => esc_url( admin_url( 'themes.php?activated=true' ) ),
     164                        'activated'     => admin_url( 'themes.php?activated=true&previewed' ),
    165165                        'ajax'          => esc_url( admin_url( 'admin-ajax.php', 'relative' ) ),
    166166                        'allowed'       => array_map( 'esc_url', $allowed_urls ),
    167167                        'isCrossDomain' => $cross_domain,
  • wp-admin/themes.php

     
    9292require_once('./admin-header.php');
    9393?>
    9494
    95 <?php if ( ! validate_current_theme() ) : ?>
    96 <div id="message1" class="updated"><p><?php _e('The active theme is broken. Reverting to the default theme.'); ?></p></div>
    97 <?php elseif ( isset($_GET['activated']) ) :
    98                 if ( isset($wp_registered_sidebars) && count( (array) $wp_registered_sidebars ) && current_user_can('edit_theme_options') ) { ?>
    99 <div id="message2" class="updated"><p><?php printf( __('New theme activated. This theme supports widgets, please visit the <a href="%s">widgets settings</a> screen to configure them.'), admin_url( 'widgets.php' ) ); ?></p></div><?php
    100                 } else { ?>
    101 <div id="message2" class="updated"><p><?php printf( __( 'New theme activated. <a href="%s">Visit site</a>' ), home_url( '/' ) ); ?></p></div><?php
    102                 }
    103         elseif ( isset($_GET['deleted']) ) : ?>
    104 <div id="message3" class="updated"><p><?php _e('Theme deleted.') ?></p></div>
    105 <?php endif; ?>
    106 
    10795<div class="wrap"><?php
    10896screen_icon();
    10997if ( ! is_multisite() && current_user_can( 'install_themes' ) ) : ?>
     
    114102<?php endif; ?>
    115103</h2>
    116104<?php
     105if ( ! validate_current_theme() || isset( $_GET['broken'] ) ) : ?>
     106<div id="message1" class="updated"><p><?php _e('The active theme is broken. Reverting to the default theme.'); ?></p></div>
     107<?php elseif ( isset($_GET['activated']) ) :
     108                if ( isset( $_GET['previewed'] ) ) { ?>
     109                <div id="message2" class="updated"><p><?php printf( __( 'Settings saved and theme activated. <a href="%s">Visit site</a>.' ), home_url( '/' ) ); ?></p></div>
     110                <?php } elseif ( isset($wp_registered_sidebars) && count( (array) $wp_registered_sidebars ) && current_user_can('edit_theme_options') ) { ?>
     111<div id="message2" class="updated"><p><?php printf( __('New theme activated. This theme supports widgets, please visit the <a href="%s">widgets settings</a> screen to configure them.'), admin_url( 'widgets.php' ) ); ?></p></div><?php
     112                } else { ?>
     113<div id="message2" class="updated"><p><?php printf( __( 'New theme activated. <a href="%s">Visit site</a>' ), home_url( '/' ) ); ?></p></div><?php
     114                }
     115        elseif ( isset($_GET['deleted']) ) : ?>
     116<div id="message3" class="updated"><p><?php _e('Theme deleted.') ?></p></div>
     117<?php
     118endif;
    117119
    118120$ct = wp_get_theme();
    119121$screenshot = $ct->get_screenshot();