Ticket #20921: 20921.2.diff

File 20921.2.diff, 6.7 KB (added by nacin, 11 months ago)
Line 
1Index: wp-includes/class-wp-customize-manager.php
2===================================================================
3--- wp-includes/class-wp-customize-manager.php  (revision 21064)
4+++ wp-includes/class-wp-customize-manager.php  (working copy)
5@@ -72,10 +72,13 @@
6         *
7         * @since 3.4.0
8         */
9-       private function wp_die( $ajax_message, $message ) {
10+       protected function wp_die( $ajax_message, $message = null ) {
11                if ( $this->doing_ajax() )
12                        wp_die( $ajax_message );
13 
14+               if ( ! $message )
15+                       $message = __( 'Cheatin’ uh?' );
16+
17                wp_die( $message );
18        }
19 
20@@ -100,29 +103,44 @@
21        public function setup_theme() {
22                if ( is_admin() && ! $this->doing_ajax() )
23                    auth_redirect();
24-               elseif ( $this->doing_ajax() && ! is_user_logged_in())
25-                   wp_die( 0 );
26+               elseif ( $this->doing_ajax() && ! is_user_logged_in() )
27+                   $this->wp_die( 0 );
28 
29+               if ( ! current_user_can( 'edit_theme_options' ) )
30+                       $this->wp_die( -1 );
31+
32                send_origin_headers();
33+               show_admin_bar( false );
34 
35                $this->original_stylesheet = get_stylesheet();
36 
37                $this->theme = wp_get_theme( isset( $_REQUEST['theme'] ) ? $_REQUEST['theme'] : null );
38 
39-               // You can't preview a theme if it doesn't exist, or if it is not allowed (unless active).
40-               if ( ! $this->theme->exists() )
41-                       $this->wp_die( -1, __( 'Cheatin’ uh?' ) );
42+               if ( $this->is_theme_active() ) {
43+                       // Once the theme is loaded, we'll validate it.
44+                       add_action( 'after_setup_theme', array( $this, 'after_setup_theme' ) );
45+               } else {
46+                       if ( ! current_user_can( 'switch_themes' ) )
47+                               $this->wp_die( -1 );
48 
49-               if ( $this->theme->get_stylesheet() != get_stylesheet() && ( ! $this->theme()->is_allowed() || ! current_user_can( 'switch_themes' ) ) )
50-                       $this->wp_die( -1, __( 'Cheatin’ uh?' ) );
51+                       // If the theme isn't active, you can't preview it if it is not allowed or has errors.
52+                       if ( $this->theme()->errors() )
53+                               $this->wp_die( -1 );
54 
55-               if ( ! current_user_can( 'edit_theme_options' ) )
56-                       $this->wp_die( -1, __( 'Cheatin’ uh?' ) );
57+                       if ( ! $this->theme()->is_allowed() )
58+                               $this->wp_die( -1 );
59+               }
60 
61                $this->start_previewing_theme();
62-               show_admin_bar( false );
63        }
64 
65+       function after_setup_theme() {
66+               if ( ! $this->doing_ajax() && ! validate_current_theme() ) {
67+                       wp_redirect( 'themes.php?broken=true' );
68+                       exit;
69+               }
70+       }
71+
72        /**
73         * Start previewing the selected theme.
74         *
75@@ -137,18 +155,20 @@
76 
77                $this->previewing = true;
78 
79-               add_filter( 'template', array( $this, 'get_template' ) );
80-               add_filter( 'stylesheet', array( $this, 'get_stylesheet' ) );
81-               add_filter( 'pre_option_current_theme', array( $this, 'current_theme' ) );
82+               if ( ! $this->is_theme_active() ) {
83+                       add_filter( 'template', array( $this, 'get_template' ) );
84+                       add_filter( 'stylesheet', array( $this, 'get_stylesheet' ) );
85+                       add_filter( 'pre_option_current_theme', array( $this, 'current_theme' ) );
86+       
87+                       // @link: http://core.trac.wordpress.org/ticket/20027
88+                       add_filter( 'pre_option_stylesheet', array( $this, 'get_stylesheet' ) );
89+                       add_filter( 'pre_option_template', array( $this, 'get_template' ) );
90+       
91+                       // Handle custom theme roots.
92+                       add_filter( 'pre_option_stylesheet_root', array( $this, 'get_stylesheet_root' ) );
93+                       add_filter( 'pre_option_template_root', array( $this, 'get_template_root' ) );
94+               }
95 
96-               // @link: http://core.trac.wordpress.org/ticket/20027
97-               add_filter( 'pre_option_stylesheet', array( $this, 'get_stylesheet' ) );
98-               add_filter( 'pre_option_template', array( $this, 'get_template' ) );
99-
100-               // Handle custom theme roots.
101-               add_filter( 'pre_option_stylesheet_root', array( $this, 'get_stylesheet_root' ) );
102-               add_filter( 'pre_option_template_root', array( $this, 'get_template_root' ) );
103-
104                do_action( 'start_previewing_theme', $this );
105        }
106 
107@@ -165,18 +185,20 @@
108 
109                $this->previewing = false;
110 
111-               remove_filter( 'template', array( $this, 'get_template' ) );
112-               remove_filter( 'stylesheet', array( $this, 'get_stylesheet' ) );
113-               remove_filter( 'pre_option_current_theme', array( $this, 'current_theme' ) );
114+               if ( ! $this->is_theme_active() ) {
115+                       remove_filter( 'template', array( $this, 'get_template' ) );
116+                       remove_filter( 'stylesheet', array( $this, 'get_stylesheet' ) );
117+                       remove_filter( 'pre_option_current_theme', array( $this, 'current_theme' ) );
118+       
119+                       // @link: http://core.trac.wordpress.org/ticket/20027
120+                       remove_filter( 'pre_option_stylesheet', array( $this, 'get_stylesheet' ) );
121+                       remove_filter( 'pre_option_template', array( $this, 'get_template' ) );
122+       
123+                       // Handle custom theme roots.
124+                       remove_filter( 'pre_option_stylesheet_root', array( $this, 'get_stylesheet_root' ) );
125+                       remove_filter( 'pre_option_template_root', array( $this, 'get_template_root' ) );
126+               }
127 
128-               // @link: http://core.trac.wordpress.org/ticket/20027
129-               remove_filter( 'pre_option_stylesheet', array( $this, 'get_stylesheet' ) );
130-               remove_filter( 'pre_option_template', array( $this, 'get_template' ) );
131-
132-               // Handle custom theme roots.
133-               remove_filter( 'pre_option_stylesheet_root', array( $this, 'get_stylesheet_root' ) );
134-               remove_filter( 'pre_option_template_root', array( $this, 'get_template_root' ) );
135-
136                do_action( 'stop_previewing_theme', $this );
137        }
138 
139@@ -389,7 +411,7 @@
140         * @return string Template name.
141         */
142        public function get_template() {
143-               return $this->theme->get_template();
144+               return $this->theme()->get_template();
145        }
146 
147        /**
148@@ -400,7 +422,7 @@
149         * @return string Stylesheet name.
150         */
151        public function get_stylesheet() {
152-               return $this->theme->get_stylesheet();
153+               return $this->theme()->get_stylesheet();
154        }
155 
156        /**
157@@ -433,7 +455,7 @@
158         * @return string Theme name.
159         */
160        public function current_theme( $current_theme ) {
161-               return $this->theme->display('Name');
162+               return $this->theme()->display('Name');
163        }
164 
165        /**
166@@ -448,7 +470,7 @@
167                check_ajax_referer( 'customize_controls-' . $this->get_stylesheet(), 'nonce' );
168 
169                // Do we have to switch themes?
170-               if ( $this->get_stylesheet() != $this->original_stylesheet ) {
171+               if ( ! $this->is_theme_active() ) {
172                        // Temporarily stop previewing the theme to allow switch_themes()
173                        // to operate properly.
174                        $this->stop_previewing_theme();
175Index: wp-admin/themes.php
176===================================================================
177--- wp-admin/themes.php (revision 21064)
178+++ wp-admin/themes.php (working copy)
179@@ -92,7 +92,7 @@
180 require_once('./admin-header.php');
181 ?>
182 
183-<?php if ( ! validate_current_theme() ) : ?>
184+<?php if ( ! validate_current_theme() || isset( $_GET['broken'] ) ) : ?>
185 <div id="message1" class="updated"><p><?php _e('The active theme is broken. Reverting to the default theme.'); ?></p></div>
186 <?php elseif ( isset($_GET['activated']) ) :
187                if ( isset($wp_registered_sidebars) && count( (array) $wp_registered_sidebars ) && current_user_can('edit_theme_options') ) { ?>