diff --git src/wp-admin/customize.php src/wp-admin/customize.php
index 7f9e5a9dc7..d22b613eeb 100644
|
|
if ( $wp_customize->changeset_post_id() ) { |
60 | 60 | } |
61 | 61 | } |
62 | 62 | |
| 63 | $is_theme_switch_unavailable = ( |
| 64 | ! $wp_customize->is_theme_active() |
| 65 | && |
| 66 | ! $wp_customize->branching() |
| 67 | && |
| 68 | $wp_customize->changeset_post_id() |
| 69 | && |
| 70 | in_array( |
| 71 | get_post_status( $wp_customize->changeset_post_id() ), |
| 72 | array_diff( get_post_stati(), array( 'auto-draft', 'publish', 'trash', 'inherit', 'private' ) ), |
| 73 | true |
| 74 | ) |
| 75 | ); |
| 76 | if ( $is_theme_switch_unavailable ) { |
| 77 | $message = sprintf( |
| 78 | /* translators: %s is URL to Customizer with the Publish Settings section auto-focused */ |
| 79 | __( 'Because you have drafted or scheduled changes, live previewing other themes is currently disabled. Please <a href="%s">publish your changes</a>, or wait until they publish to preview new themes. ' ), |
| 80 | add_query_arg( |
| 81 | array( |
| 82 | 'autofocus[section]' => 'publish_settings', |
| 83 | 'return' => admin_url( 'themes.php' ), |
| 84 | ), |
| 85 | admin_url( 'customize.php' ) |
| 86 | ) |
| 87 | ); |
| 88 | |
| 89 | wp_die( |
| 90 | '<h1>' . __( 'Cheatin’ uh?' ) . '</h1>' . |
| 91 | '<p>' . $message . '</p>', |
| 92 | 403 |
| 93 | ); |
| 94 | } |
| 95 | |
63 | 96 | |
64 | 97 | wp_reset_vars( array( 'url', 'return', 'autofocus' ) ); |
65 | 98 | if ( ! empty( $url ) ) { |
diff --git src/wp-admin/theme-install.php src/wp-admin/theme-install.php
index 43f105f377..0ede57849e 100644
|
|
get_current_screen()->set_help_sidebar( |
123 | 123 | |
124 | 124 | include(ABSPATH . 'wp-admin/admin-header.php'); |
125 | 125 | |
| 126 | $is_customize_preview_available = true; |
| 127 | |
| 128 | /** This filter is documented in wp-includes/class-wp-customize-manager.php */ |
| 129 | if ( ! apply_filters( 'customize_changeset_branching', false ) ) { |
| 130 | $is_customize_preview_available = count( get_posts( array( |
| 131 | 'post_type' => 'customize_changeset', |
| 132 | 'post_status' => array_diff( get_post_stati(), array( 'auto-draft', 'publish', 'trash', 'inherit', 'private' ) ), |
| 133 | 'author' => 'any', |
| 134 | 'posts_per_page' => 1, |
| 135 | 'no_found_rows' => true, |
| 136 | 'cache_results' => true, |
| 137 | 'update_post_meta_cache' => false, |
| 138 | 'update_post_term_cache' => false, |
| 139 | 'lazy_load_term_meta' => false, |
| 140 | ) ) ) === 0; |
| 141 | } |
| 142 | |
126 | 143 | ?> |
127 | 144 | <div class="wrap"> |
128 | 145 | <h1 class="wp-heading-inline"><?php echo esc_html( $title ); ?></h1> |
… |
… |
include(ABSPATH . 'wp-admin/admin-header.php'); |
150 | 167 | <p><?php _e( 'The Theme Installer screen requires JavaScript.' ); ?></p> |
151 | 168 | </div> |
152 | 169 | |
| 170 | <?php if ( ! $is_customize_preview_available ) : ?> |
| 171 | <div class="notice notice-info"> |
| 172 | <p> |
| 173 | <?php |
| 174 | printf( |
| 175 | /* translators: %s is URL to Customizer with the Publish Settings section auto-focused */ |
| 176 | __( 'Because you have drafted or scheduled changes, live previewing other themes is currently disabled. Please <a href="%s">publish your changes</a>, or wait until they publish to preview new themes. ' ), |
| 177 | add_query_arg( 'autofocus[section]', 'publish_settings', admin_url( 'customize.php' ) ) |
| 178 | ); |
| 179 | ?> |
| 180 | </p> |
| 181 | </div> |
| 182 | <?php endif; ?> |
| 183 | |
153 | 184 | <div class="upload-theme"> |
154 | 185 | <?php install_themes_upload(); ?> |
155 | 186 | </div> |
… |
… |
if ( $tab ) { |
277 | 308 | <# if ( data.activate_url ) { #> |
278 | 309 | <a class="button button-primary activate" href="{{ data.activate_url }}" aria-label="<?php echo esc_attr( $aria_label ); ?>"><?php _e( 'Activate' ); ?></a> |
279 | 310 | <# } #> |
280 | | <# if ( data.customize_url ) { #> |
| 311 | <# if ( data.customize_url && <?php echo wp_json_encode( $is_customize_preview_available ); ?> ) { #> |
281 | 312 | <a class="button load-customize" href="{{ data.customize_url }}"><?php _e( 'Live Preview' ); ?></a> |
282 | 313 | <# } else { #> |
283 | 314 | <button class="button preview install-theme-preview"><?php _e( 'Preview' ); ?></button> |
diff --git src/wp-admin/themes.php src/wp-admin/themes.php
index 9218983239..6ffa58659b 100644
|
|
wp_enqueue_script( 'theme' ); |
148 | 148 | wp_enqueue_script( 'updates' ); |
149 | 149 | |
150 | 150 | require_once( ABSPATH . 'wp-admin/admin-header.php' ); |
| 151 | |
| 152 | $is_customize_preview_available = true; |
| 153 | |
| 154 | /** This filter is documented in wp-includes/class-wp-customize-manager.php */ |
| 155 | if ( ! apply_filters( 'customize_changeset_branching', false ) ) { |
| 156 | $is_customize_preview_available = count( get_posts( array( |
| 157 | 'post_type' => 'customize_changeset', |
| 158 | 'post_status' => array_diff( get_post_stati(), array( 'auto-draft', 'publish', 'trash', 'inherit', 'private' ) ), |
| 159 | 'author' => 'any', |
| 160 | 'posts_per_page' => 1, |
| 161 | 'no_found_rows' => true, |
| 162 | 'cache_results' => true, |
| 163 | 'update_post_meta_cache' => false, |
| 164 | 'update_post_term_cache' => false, |
| 165 | 'lazy_load_term_meta' => false, |
| 166 | ) ) ) === 0; |
| 167 | } |
| 168 | |
151 | 169 | ?> |
152 | 170 | |
153 | 171 | <div class="wrap"> |
… |
… |
if ( ! validate_current_theme() || isset( $_GET['broken'] ) ) : ?> |
178 | 196 | <?php |
179 | 197 | endif; |
180 | 198 | |
| 199 | if ( ! $is_customize_preview_available ) : |
| 200 | ?> |
| 201 | <div class="notice notice-info"> |
| 202 | <p> |
| 203 | <?php |
| 204 | printf( |
| 205 | /* translators: %s is URL to Customizer with the Publish Settings section auto-focused */ |
| 206 | __( 'Because you have drafted or scheduled changes, live previewing other themes is currently disabled. Please <a href="%s">publish your changes</a>, or wait until they publish to preview new themes. ' ), |
| 207 | add_query_arg( 'autofocus[section]', 'publish_settings', admin_url( 'customize.php' ) ) |
| 208 | ); |
| 209 | ?> |
| 210 | </p> |
| 211 | </div> |
| 212 | <?php |
| 213 | endif; |
| 214 | |
181 | 215 | $ct = wp_get_theme(); |
182 | 216 | |
183 | 217 | if ( $ct->errors() && ( ! is_multisite() || current_user_can( 'manage_network_themes' ) ) ) { |
… |
… |
foreach ( $themes as $theme ) : |
296 | 330 | $aria_label = sprintf( _x( 'Activate %s', 'theme' ), '{{ data.name }}' ); |
297 | 331 | ?> |
298 | 332 | <a class="button activate" href="<?php echo $theme['actions']['activate']; ?>" aria-label="<?php echo esc_attr( $aria_label ); ?>"><?php _e( 'Activate' ); ?></a> |
299 | | <?php if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { ?> |
| 333 | <?php if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) && $is_customize_preview_available ) { ?> |
300 | 334 | <a class="button button-primary load-customize hide-if-no-customize" href="<?php echo $theme['actions']['customize']; ?>"><?php _e( 'Live Preview' ); ?></a> |
301 | 335 | <?php } ?> |
302 | 336 | <?php } ?> |
… |
… |
$can_install = current_user_can( 'install_themes' ); |
431 | 465 | $aria_label = sprintf( _x( 'Activate %s', 'theme' ), '{{ data.name }}' ); |
432 | 466 | ?> |
433 | 467 | <a class="button activate" href="{{{ data.actions.activate }}}" aria-label="<?php echo $aria_label; ?>"><?php _e( 'Activate' ); ?></a> |
434 | | <a class="button button-primary load-customize hide-if-no-customize" href="{{{ data.actions.customize }}}"><?php _e( 'Live Preview' ); ?></a> |
| 468 | <?php if ( $is_customize_preview_available ) : ?> |
| 469 | <a class="button button-primary load-customize hide-if-no-customize" href="{{{ data.actions.customize }}}"><?php _e( 'Live Preview' ); ?></a> |
| 470 | <?php endif; ?> |
435 | 471 | <# } #> |
436 | 472 | </div> |
437 | 473 | </div> |
… |
… |
$can_install = current_user_can( 'install_themes' ); |
492 | 528 | <# if ( data.actions.activate ) { #> |
493 | 529 | <a href="{{{ data.actions.activate }}}" class="button activate" aria-label="<?php echo $aria_label; ?>"><?php _e( 'Activate' ); ?></a> |
494 | 530 | <# } #> |
495 | | <a href="{{{ data.actions.customize }}}" class="button button-primary load-customize hide-if-no-customize"><?php _e( 'Live Preview' ); ?></a> |
| 531 | <?php if ( $is_customize_preview_available ) : ?> |
| 532 | <a href="{{{ data.actions.customize }}}" class="button button-primary load-customize hide-if-no-customize"><?php _e( 'Live Preview' ); ?></a> |
| 533 | <?php endif; ?> |
496 | 534 | </div> |
497 | 535 | |
498 | 536 | <# if ( ! data.active && data.actions['delete'] ) { #> |
diff --git src/wp-includes/class-wp-customize-manager.php src/wp-includes/class-wp-customize-manager.php
index 12256d2173..3cd93ce423 100644
|
|
final class WP_Customize_Manager { |
612 | 612 | if ( empty( $this->_changeset_uuid ) ) { |
613 | 613 | $changeset_uuid = null; |
614 | 614 | |
615 | | if ( ! $this->branching() && $this->is_theme_active() ) { |
| 615 | if ( ! $this->branching() ) { |
616 | 616 | $unpublished_changeset_posts = $this->get_changeset_posts( array( |
617 | 617 | 'post_status' => array_diff( get_post_stati(), array( 'auto-draft', 'publish', 'trash', 'inherit', 'private' ) ), |
618 | 618 | 'exclude_restore_dismissed' => false, |
… |
… |
final class WP_Customize_Manager { |
782 | 782 | * |
783 | 783 | * @since 4.9.0 |
784 | 784 | * |
785 | | * @param bool $allow_branching Whether branching is allowed. If `false`, the default, |
786 | | * then only one saved changeset exists at a time. |
787 | | * @param WP_Customize_Manager $wp_customize Manager instance. |
| 785 | * @param bool $allow_branching Whether branching is allowed. If `false`, the default, |
| 786 | * then only one saved changeset exists at a time. |
788 | 787 | */ |
789 | | $this->branching = apply_filters( 'customize_changeset_branching', $this->branching, $this ); |
| 788 | $this->branching = apply_filters( 'customize_changeset_branching', $this->branching ); |
790 | 789 | |
791 | 790 | return $this->branching; |
792 | 791 | } |
diff --git tests/phpunit/tests/customize/manager.php tests/phpunit/tests/customize/manager.php
index 1152efd983..18f00afb1b 100644
|
|
class Tests_WP_Customize_Manager extends WP_UnitTestCase { |
197 | 197 | ) ); |
198 | 198 | $this->assertNotContains( $wp_customize->changeset_uuid(), array( $uuid1, $uuid2 ) ); |
199 | 199 | $this->assertEmpty( $wp_customize->changeset_post_id() ); |
200 | | |
201 | | // Make sure existing changeset is not autoloaded in the case of previewing a theme switch. |
202 | | switch_theme( 'twentyseventeen' ); |
203 | | $wp_customize = new WP_Customize_Manager( array( |
204 | | 'changeset_uuid' => false, // Cause UUID to be deferred. |
205 | | 'branching' => false, |
206 | | 'theme' => 'twentyfifteen', |
207 | | ) ); |
208 | | $this->assertEmpty( $wp_customize->changeset_post_id() ); |
209 | 200 | } |
210 | 201 | |
211 | 202 | /** |