Make WordPress Core

Changeset 42113


Ignore:
Timestamp:
11/03/2017 12:58:25 AM (7 years ago)
Author:
westonruter
Message:

Customize: Make sure theme switch blocking in the Customizer is consistently applied when changeset is drafted/scheduled.

  • Consider both selectedChangesetStatus and changesetStatus states when deciding to disable.
  • Factor out common logic into canSwitchTheme function on ThemesPanel.
  • Keep Live Preview and Install buttons disabled in Themes controls and detail overlays when appropriate.

Props westonruter, dlh.
Amends [41788].
See #42126, #37661, #39896.
Fixes #42406.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/customize-controls.js

    r42104 r42113  
    25502550         */
    25512551        showDetails: function ( theme, callback ) {
    2552             var section = this;
     2552            var section = this, panel = api.panel( 'themes' );
    25532553            section.currentTheme = theme.id;
    25542554            section.overlay.html( section.template( theme ) )
    25552555                .fadeIn( 'fast' )
    25562556                .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
    25572570            section.$body.addClass( 'modal-open' );
    25582571            section.containFocus( section.overlay );
     
    30323045
    30333046        /**
     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
     3061        /**
    30343062         * Attach events.
    30353063         *
     
    30533081
    30543082            function toggleDisabledNotifications() {
    3055                 if ( 'publish' === api.state( 'selectedChangesetStatus' ).get() ) {
     3083                if ( panel.canSwitchTheme() ) {
    30563084                    panel.notifications.remove( 'theme_switch_unavailable' );
    30573085                } else {
     
    30643092            toggleDisabledNotifications();
    30653093            api.state( 'selectedChangesetStatus' ).bind( toggleDisabledNotifications );
     3094            api.state( 'changesetStatus' ).bind( toggleDisabledNotifications );
    30663095
    30673096            // Collapse panel to customize the current theme.
     
    31743203
    31753204            // 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 ) ) {
    31773206                deferred.reject({
    31783207                    errorCode: 'theme_switch_unavailable'
     
    32673296         */
    32683297        loadThemePreview: function( themeId ) {
    3269             var deferred = $.Deferred(), onceProcessingComplete, urlParser, queryParams;
     3298            var panel = this, deferred = $.Deferred(), onceProcessingComplete, urlParser, queryParams;
    32703299
    32713300            // 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 ) ) {
    32733302                return deferred.reject().promise();
    32743303            }
     
    50905119         */
    50915120        ready: function() {
    5092             var control = this;
     5121            var control = this, panel = api.panel( 'themes' );
    50935122
    50945123            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 );
    50965125            }
    50975126
     
    51005129                return disableSwitchButtons() || true === api.settings.theme._filesystemCredentialsNeeded;
    51015130            }
    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() );
    5106             }
    5107 
    5108             api.state( 'selectedChangesetStatus' ).bind( function() {
    5109                 updateButtons();
    5110             });
     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() );
     5134            }
     5135
     5136            api.state( 'selectedChangesetStatus' ).bind( updateButtons );
     5137            api.state( 'changesetStatus' ).bind( updateButtons );
    51115138            updateButtons();
    51125139
     
    51355162                section = api.section( control.section() );
    51365163                section.showDetails( control.params.theme, function() {
    5137                     updateButtons( section.overlay.find( '.theme-actions' ) );
    51385164
    51395165                    // Temporary special function since supplying SFTP credentials does not work yet. See #42184.
Note: See TracChangeset for help on using the changeset viewer.