diff --git src/wp-admin/js/customize-controls.js src/wp-admin/js/customize-controls.js
index 7fb87bc88e..5110db234a 100644
|
|
|
3030 | 3030 | api.Panel.prototype.initialize.call( panel, id, options ); |
3031 | 3031 | }, |
3032 | 3032 | |
| 3033 | /** |
| 3034 | * Determine whether a given theme can be switched to, or in general. |
| 3035 | * |
| 3036 | * @since 4.9.0 |
| 3037 | * |
| 3038 | * @param {string} [slug] - Theme slug. |
| 3039 | * @returns {boolean} Whether the theme can be switched to. |
| 3040 | */ |
| 3041 | canSwitchTheme: function canSwitchTheme( slug ) { |
| 3042 | if ( slug && slug === api.settings.theme.stylesheet ) { |
| 3043 | return true; |
| 3044 | } |
| 3045 | return 'publish' === api.state( 'selectedChangesetStatus' ).get() && ( '' === api.state( 'changesetStatus' ).get() || 'auto-draft' === api.state( 'changesetStatus' ).get() ); |
| 3046 | }, |
| 3047 | |
3033 | 3048 | /** |
3034 | 3049 | * Attach events. |
3035 | 3050 | * |
… |
… |
|
3052 | 3067 | } |
3053 | 3068 | |
3054 | 3069 | function toggleDisabledNotifications() { |
3055 | | if ( 'publish' === api.state( 'selectedChangesetStatus' ).get() ) { |
| 3070 | if ( panel.canSwitchTheme() ) { |
3056 | 3071 | panel.notifications.remove( 'theme_switch_unavailable' ); |
3057 | 3072 | } else { |
3058 | 3073 | panel.notifications.add( new api.Notification( 'theme_switch_unavailable', { |
… |
… |
|
3063 | 3078 | } |
3064 | 3079 | toggleDisabledNotifications(); |
3065 | 3080 | api.state( 'selectedChangesetStatus' ).bind( toggleDisabledNotifications ); |
| 3081 | api.state( 'changesetStatus' ).bind( toggleDisabledNotifications ); |
3066 | 3082 | |
3067 | 3083 | // Collapse panel to customize the current theme. |
3068 | 3084 | panel.contentContainer.on( 'click', '.customize-theme', function() { |
… |
… |
|
3173 | 3189 | } |
3174 | 3190 | |
3175 | 3191 | // Prevent loading a non-active theme preview when there is a drafted/scheduled changeset. |
3176 | | if ( 'publish' !== api.state( 'selectedChangesetStatus' ).get() && slug !== api.settings.theme.stylesheet ) { |
| 3192 | if ( panel.canSwitchTheme( slug ) ) { |
3177 | 3193 | deferred.reject({ |
3178 | 3194 | errorCode: 'theme_switch_unavailable' |
3179 | 3195 | }); |
… |
… |
|
3266 | 3282 | * @returns {jQuery.promise} Promise. |
3267 | 3283 | */ |
3268 | 3284 | loadThemePreview: function( themeId ) { |
3269 | | var deferred = $.Deferred(), onceProcessingComplete, urlParser, queryParams; |
| 3285 | var panel = this, deferred = $.Deferred(), onceProcessingComplete, urlParser, queryParams; |
3270 | 3286 | |
3271 | 3287 | // Prevent loading a non-active theme preview when there is a drafted/scheduled changeset. |
3272 | | if ( 'publish' !== api.state( 'selectedChangesetStatus' ).get() && themeId !== api.settings.theme.stylesheet ) { |
| 3288 | if ( ! panel.canSwitchTheme( themeId ) ) { |
3273 | 3289 | return deferred.reject().promise(); |
3274 | 3290 | } |
3275 | 3291 | |
… |
… |
|
5089 | 5105 | * @since 4.2.0 |
5090 | 5106 | */ |
5091 | 5107 | ready: function() { |
5092 | | var control = this; |
| 5108 | var control = this, panel = api.panel( 'themes' ); |
5093 | 5109 | |
5094 | 5110 | function disableSwitchButtons() { |
5095 | | return 'publish' !== api.state( 'selectedChangesetStatus' ).get() && control.params.theme.id !== api.settings.theme.stylesheet; |
| 5111 | return ! panel.canSwitchTheme( control.params.theme.id ); |
5096 | 5112 | } |
5097 | 5113 | |
5098 | 5114 | // Temporary special function since supplying SFTP credentials does not work yet. See #42184. |
… |
… |
|
5107 | 5123 | |
5108 | 5124 | api.state( 'selectedChangesetStatus' ).bind( function() { |
5109 | 5125 | updateButtons(); |
5110 | | }); |
| 5126 | } ); |
| 5127 | api.state( 'changesetStatus' ).bind( function() { |
| 5128 | updateButtons(); |
| 5129 | } ); |
5111 | 5130 | updateButtons(); |
5112 | 5131 | |
5113 | 5132 | control.container.on( 'touchmove', '.theme', function() { |