Changeset 20584 for trunk/wp-includes/class-wp-customize.php
- Timestamp:
- 04/25/2012 03:44:06 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/class-wp-customize.php
r20572 r20584 28 28 require( ABSPATH . WPINC . '/class-wp-customize-control.php' ); 29 29 30 add_action( 'setup_theme', array( $this, ' customize_previewing' ) );30 add_action( 'setup_theme', array( $this, 'setup_theme' ) ); 31 31 add_action( 'admin_init', array( $this, 'admin_init' ) ); 32 32 add_action( 'wp_loaded', array( $this, 'wp_loaded' ) ); … … 62 62 * @since 3.4.0 63 63 */ 64 public function customize_previewing() {64 public function setup_theme() { 65 65 if ( ! isset( $_REQUEST['customize'] ) || 'on' != $_REQUEST['customize'] ) 66 66 return; 67 67 68 if ( ! $this->set_theme() || isset( $_REQUEST['save_customize_controls'] ) ) 69 return; 68 $this->start_previewing_theme(); 69 show_admin_bar( false ); 70 } 71 72 /** 73 * Start previewing the selected theme. 74 * 75 * Adds filters to change the current theme. 76 * 77 * @since 3.4.0 78 */ 79 public function start_previewing_theme() { 80 if ( $this->is_preview() || false === $this->theme || ( $this->theme && ! $this->theme->exists() ) ) 81 return; 82 83 // Initialize $theme and $original_stylesheet if they do not yet exist. 84 if ( ! isset( $this->theme ) ) { 85 $this->theme = wp_get_theme( $_REQUEST['theme'] ); 86 if ( ! $this->theme->exists() ) { 87 $this->theme = false; 88 return; 89 } 90 } 91 92 $this->original_stylesheet = get_stylesheet(); 70 93 71 94 $this->previewing = true; 72 73 show_admin_bar( false );74 75 $this->original_stylesheet = get_stylesheet();76 95 77 96 add_filter( 'template', array( $this, 'get_template' ) ); … … 87 106 add_filter( 'pre_option_template_root', array( $this, 'get_template_root' ) ); 88 107 89 do_action( 'customize_previewing' ); 108 do_action( 'start_previewing_theme' ); 109 } 110 111 /** 112 * Stop previewing the selected theme. 113 * 114 * Removes filters to change the current theme. 115 * 116 * @since 3.4.0 117 */ 118 public function stop_previewing_theme() { 119 if ( ! $this->is_preview() ) 120 return; 121 122 $this->previewing = false; 123 124 remove_filter( 'template', array( $this, 'get_template' ) ); 125 remove_filter( 'stylesheet', array( $this, 'get_stylesheet' ) ); 126 remove_filter( 'pre_option_current_theme', array( $this, 'current_theme' ) ); 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' ); 90 137 } 91 138 … … 161 208 162 209 /** 163 * Set the stylesheet name of the previewed theme.164 *165 * @since 3.4.0166 *167 * @return bool|string Stylesheet name.168 */169 public function set_theme() {170 if ( isset( $this->theme ) )171 return $this->theme;172 173 $this->theme = wp_get_theme( $_REQUEST['theme'] );174 if ( ! $this->theme->exists() )175 $this->theme = false;176 177 return $this->theme;178 }179 180 /**181 210 * Retrieve the template name of the previewed theme. 182 211 * … … 268 297 */ 269 298 public function save() { 270 if ( $this->is_preview() )299 if ( ! $this->is_preview() ) 271 300 return; 272 301 273 302 check_admin_referer( 'customize_controls' ); 274 303 275 if ( ! $this->set_theme() )276 return;277 278 $active_template = get_template();279 $active_stylesheet = get_stylesheet();280 281 304 // Do we have to switch themes? 282 if ( $this->get_ template() != $active_template || $this->get_stylesheet() != $active_stylesheet ) {305 if ( $this->get_stylesheet() != $this->original_stylesheet ) { 283 306 if ( ! current_user_can( 'switch_themes' ) ) 284 307 return; 285 308 309 // Temporarily stop previewing the theme to allow switch_themes() 310 // to operate properly. 311 $this->stop_previewing_theme(); 286 312 switch_theme( $this->get_template(), $this->get_stylesheet() ); 313 $this->start_previewing_theme(); 287 314 } 288 315
Note: See TracChangeset
for help on using the changeset viewer.