diff --git src/wp-admin/js/customize-controls.js src/wp-admin/js/customize-controls.js
index 7fb87bc88e..fbb8f42959 100644
|
|
|
2549 | 2549 | * @returns {void} |
2550 | 2550 | */ |
2551 | 2551 | showDetails: function ( theme, callback ) { |
2552 | | var section = this; |
| 2552 | var section = this, panel = api.panel( 'themes' ); |
2553 | 2553 | section.currentTheme = theme.id; |
2554 | 2554 | section.overlay.html( section.template( theme ) ) |
2555 | 2555 | .fadeIn( 'fast' ) |
2556 | 2556 | .focus(); |
| 2557 | |
| 2558 | function disableSwitchButtons() { |
| 2559 | return ! panel.canSwitchTheme( theme.id ); |
| 2560 | } |
| 2561 | |
| 2562 | // Temporary special function since supplying SFTP credentials does not work yet. See #42184. |
| 2563 | function disableInstallButtons() { |
| 2564 | return disableSwitchButtons() || true === api.settings.theme._filesystemCredentialsNeeded; |
| 2565 | } |
| 2566 | |
| 2567 | section.overlay.find( 'button.preview, button.preview-theme' ).toggleClass( 'disabled', disableSwitchButtons() ); |
| 2568 | section.overlay.find( 'button.theme-install' ).toggleClass( 'disabled', disableInstallButtons() ); |
| 2569 | |
2557 | 2570 | section.$body.addClass( 'modal-open' ); |
2558 | 2571 | section.containFocus( section.overlay ); |
2559 | 2572 | section.updateLimits(); |
… |
… |
|
3030 | 3043 | api.Panel.prototype.initialize.call( panel, id, options ); |
3031 | 3044 | }, |
3032 | 3045 | |
| 3046 | /** |
| 3047 | * Determine whether a given theme can be switched to, or in general. |
| 3048 | * |
| 3049 | * @since 4.9.0 |
| 3050 | * |
| 3051 | * @param {string} [slug] - Theme slug. |
| 3052 | * @returns {boolean} Whether the theme can be switched to. |
| 3053 | */ |
| 3054 | canSwitchTheme: function canSwitchTheme( slug ) { |
| 3055 | if ( slug && slug === api.settings.theme.stylesheet ) { |
| 3056 | return true; |
| 3057 | } |
| 3058 | return 'publish' === api.state( 'selectedChangesetStatus' ).get() && ( '' === api.state( 'changesetStatus' ).get() || 'auto-draft' === api.state( 'changesetStatus' ).get() ); |
| 3059 | }, |
| 3060 | |
3033 | 3061 | /** |
3034 | 3062 | * Attach events. |
3035 | 3063 | * |
… |
… |
|
3052 | 3080 | } |
3053 | 3081 | |
3054 | 3082 | function toggleDisabledNotifications() { |
3055 | | if ( 'publish' === api.state( 'selectedChangesetStatus' ).get() ) { |
| 3083 | if ( panel.canSwitchTheme() ) { |
3056 | 3084 | panel.notifications.remove( 'theme_switch_unavailable' ); |
3057 | 3085 | } else { |
3058 | 3086 | panel.notifications.add( new api.Notification( 'theme_switch_unavailable', { |
… |
… |
|
3063 | 3091 | } |
3064 | 3092 | toggleDisabledNotifications(); |
3065 | 3093 | api.state( 'selectedChangesetStatus' ).bind( toggleDisabledNotifications ); |
| 3094 | api.state( 'changesetStatus' ).bind( toggleDisabledNotifications ); |
3066 | 3095 | |
3067 | 3096 | // Collapse panel to customize the current theme. |
3068 | 3097 | panel.contentContainer.on( 'click', '.customize-theme', function() { |
… |
… |
|
3173 | 3202 | } |
3174 | 3203 | |
3175 | 3204 | // 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 ) { |
| 3205 | if ( panel.canSwitchTheme( slug ) ) { |
3177 | 3206 | deferred.reject({ |
3178 | 3207 | errorCode: 'theme_switch_unavailable' |
3179 | 3208 | }); |
… |
… |
|
3266 | 3295 | * @returns {jQuery.promise} Promise. |
3267 | 3296 | */ |
3268 | 3297 | loadThemePreview: function( themeId ) { |
3269 | | var deferred = $.Deferred(), onceProcessingComplete, urlParser, queryParams; |
| 3298 | var panel = this, deferred = $.Deferred(), onceProcessingComplete, urlParser, queryParams; |
3270 | 3299 | |
3271 | 3300 | // 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 ) { |
| 3301 | if ( ! panel.canSwitchTheme( themeId ) ) { |
3273 | 3302 | return deferred.reject().promise(); |
3274 | 3303 | } |
3275 | 3304 | |
… |
… |
|
5089 | 5118 | * @since 4.2.0 |
5090 | 5119 | */ |
5091 | 5120 | ready: function() { |
5092 | | var control = this; |
| 5121 | var control = this, panel = api.panel( 'themes' ); |
5093 | 5122 | |
5094 | 5123 | function disableSwitchButtons() { |
5095 | | return 'publish' !== api.state( 'selectedChangesetStatus' ).get() && control.params.theme.id !== api.settings.theme.stylesheet; |
| 5124 | return ! panel.canSwitchTheme( control.params.theme.id ); |
5096 | 5125 | } |
5097 | 5126 | |
5098 | 5127 | // Temporary special function since supplying SFTP credentials does not work yet. See #42184. |
5099 | 5128 | function disableInstallButtons() { |
5100 | 5129 | return disableSwitchButtons() || true === api.settings.theme._filesystemCredentialsNeeded; |
5101 | 5130 | } |
5102 | | function updateButtons( container ) { |
5103 | | var _container = container || control.container; |
5104 | | _container.find( 'button.preview, button.preview-theme' ).toggleClass( 'disabled', disableSwitchButtons() ); |
5105 | | _container.find( 'button.theme-install' ).toggleClass( 'disabled', disableInstallButtons() ); |
| 5131 | function updateButtons() { |
| 5132 | control.container.find( 'button.preview, button.preview-theme' ).toggleClass( 'disabled', disableSwitchButtons() ); |
| 5133 | control.container.find( 'button.theme-install' ).toggleClass( 'disabled', disableInstallButtons() ); |
5106 | 5134 | } |
5107 | 5135 | |
5108 | | api.state( 'selectedChangesetStatus' ).bind( function() { |
5109 | | updateButtons(); |
5110 | | }); |
| 5136 | api.state( 'selectedChangesetStatus' ).bind( updateButtons ); |
| 5137 | api.state( 'changesetStatus' ).bind( updateButtons ); |
5111 | 5138 | updateButtons(); |
5112 | 5139 | |
5113 | 5140 | control.container.on( 'touchmove', '.theme', function() { |
… |
… |
|
5134 | 5161 | event.preventDefault(); // Keep this AFTER the key filter above |
5135 | 5162 | section = api.section( control.section() ); |
5136 | 5163 | section.showDetails( control.params.theme, function() { |
5137 | | updateButtons( section.overlay.find( '.theme-actions' ) ); |
5138 | 5164 | |
5139 | 5165 | // Temporary special function since supplying SFTP credentials does not work yet. See #42184. |
5140 | 5166 | if ( api.settings.theme._filesystemCredentialsNeeded ) { |