WordPress.org

Make WordPress Core

Changeset 41997


Ignore:
Timestamp:
10/24/2017 07:05:48 PM (20 months ago)
Author:
westonruter
Message:

Customize: Prevent theme installation and deletion in Customizer while SFTP credentials need to be requested.

This is a temporary measure while we wait for credentials to be able to be supplied in the Customizer.

Amends [41788].
See #42184, #37661, #42126.

Location:
trunk/src
Files:
3 edited

Legend:

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

    r41969 r41997  
    29872987         */
    29882988        attachEvents: function() {
    2989             var panel = this, toggleDisabledNotification;
     2989            var panel = this;
    29902990
    29912991            // Attach regular panel events.
    29922992            api.Panel.prototype.attachEvents.apply( panel );
    29932993
    2994             toggleDisabledNotification = function() {
     2994            // Temporary since supplying SFTP credentials does not work yet. See #42184
     2995            if ( api.settings.theme._filesystemCredentialsNeeded ) {
     2996                panel.notifications.add( new api.Notification( 'theme_install_unavailable', {
     2997                    message: api.l10n.themeInstallUnavailable,
     2998                    type: 'info',
     2999                    dismissible: true
     3000                } ) );
     3001            }
     3002
     3003            function toggleDisabledNotifications() {
    29953004                if ( 'publish' === api.state( 'selectedChangesetStatus' ).get() ) {
    29963005                    panel.notifications.remove( 'theme_switch_unavailable' );
     
    30013010                    } ) );
    30023011                }
    3003             };
    3004             toggleDisabledNotification();
    3005             api.state( 'selectedChangesetStatus' ).bind( toggleDisabledNotification );
     3012            }
     3013            toggleDisabledNotifications();
     3014            api.state( 'selectedChangesetStatus' ).bind( toggleDisabledNotifications );
    30063015
    30073016            // Collapse panel to customize the current theme.
     
    30963105            var panel = this, preview, onInstallSuccess, slug = $( event.target ).data( 'slug' ), deferred = $.Deferred(), request;
    30973106            preview = $( event.target ).hasClass( 'preview' );
     3107
     3108            // Temporary since supplying SFTP credentials does not work yet. See #42184.
     3109            if ( api.settings.theme._filesystemCredentialsNeeded ) {
     3110                deferred.reject({
     3111                    errorCode: 'theme_install_unavailable'
     3112                });
     3113                return deferred.promise();
     3114            }
    30983115
    30993116            // Prevent loading a non-active theme preview when there is a drafted/scheduled changeset.
     
    32963313
    32973314            event.preventDefault();
     3315
     3316            // Temporary since supplying SFTP credentials does not work yet. See #42184.
     3317            if ( api.settings.theme._filesystemCredentialsNeeded ) {
     3318                return;
     3319            }
    32983320
    32993321            // Confirmation dialog for deleting a theme.
     
    49845006         */
    49855007        ready: function() {
    4986             var control = this, disableSwitchButtons, updateButtons;
    4987 
    4988             disableSwitchButtons = function() {
     5008            var control = this;
     5009
     5010            function disableSwitchButtons() {
    49895011                return 'publish' !== api.state( 'selectedChangesetStatus' ).get() && control.params.theme.id !== api.settings.theme.stylesheet;
    4990             };
    4991             updateButtons = function() {
    4992                 control.container.find( 'button' ).toggleClass( 'disabled', disableSwitchButtons() );
    4993             };
    4994 
    4995             api.state( 'selectedChangesetStatus' ).bind( updateButtons );
     5012            }
     5013
     5014            // Temporary special function since supplying SFTP credentials does not work yet. See #42184.
     5015            function disableInstallButtons() {
     5016                return disableSwitchButtons() || true === api.settings.theme._filesystemCredentialsNeeded;
     5017            }
     5018            function updateButtons( container ) {
     5019                var _container = container || control.container;
     5020                _container.find( 'button.preview, button.preview-theme' ).toggleClass( 'disabled', disableSwitchButtons() );
     5021                _container.find( 'button.theme-install' ).toggleClass( 'disabled', disableInstallButtons() );
     5022            }
     5023
     5024            api.state( 'selectedChangesetStatus' ).bind( function() {
     5025                updateButtons();
     5026            });
    49965027            updateButtons();
    49975028
     
    50205051                section = api.section( control.section() );
    50215052                section.showDetails( control.params.theme, function() {
    5022                     section.overlay.find( '.theme-actions button' ).toggleClass( 'disabled', disableSwitchButtons() );
     5053                    updateButtons( section.overlay.find( '.theme-actions' ) );
     5054
     5055                    // Temporary special function since supplying SFTP credentials does not work yet. See #42184.
     5056                    if ( api.settings.theme._filesystemCredentialsNeeded ) {
     5057                        section.overlay.find( '.theme-actions .delete-theme' ).remove();
     5058                    }
    50235059                } );
    50245060            });
  • trunk/src/wp-includes/class-wp-customize-manager.php

    r41989 r41997  
    46194619        );
    46204620
     4621        // Temporarily disable installation in Customizer. See #42184.
     4622        $filesystem_method = get_filesystem_method();
     4623        ob_start();
     4624        $filesystem_credentials_are_stored = request_filesystem_credentials( self_admin_url() );
     4625        ob_end_clean();
     4626        if ( 'direct' !== $filesystem_method && ! $filesystem_credentials_are_stored ) {
     4627            $settings['theme']['_filesystemCredentialsNeeded'] = true;
     4628        }
     4629
    46214630        // Prepare Customize Section objects to pass to JavaScript.
    46224631        foreach ( $this->sections() as $id => $section ) {
  • trunk/src/wp-includes/script-loader.php

    r41977 r41997  
    594594        'scheduleDescription' => __( 'Schedule your customization changes to publish ("go live") at a future date.' ),
    595595        'themePreviewUnavailable' => __( 'Sorry, you can’t preview new themes when you have changes scheduled or saved as a draft. Please publish your changes, or wait until they publish to preview new themes.' ),
     596        'themeInstallUnavailable' => sprintf(
     597            /* translators: %s is URL to Add Themes admin screen */
     598            __( 'You won&#8217;t be able to install new themes from here yet since your install requires SFTP credentials. For now, please <a href="%s">add themes in the admin</a>.' ),
     599            esc_url( admin_url( 'theme-install.php' ) )
     600        ),
    596601    ) );
    597602    $scripts->add( 'customize-selective-refresh', "/wp-includes/js/customize-selective-refresh$suffix.js", array( 'jquery', 'wp-util', 'customize-preview' ), false, 1 );
Note: See TracChangeset for help on using the changeset viewer.