Make WordPress Core

Ticket #31294: 31294.4.diff

File 31294.4.diff, 5.2 KB (added by ocean90, 10 years ago)
  • src/wp-admin/js/customize-controls.js

     
    23582358
    23592359                        messenger.targetWindow( iframe[0].contentWindow );
    23602360
    2361                         messenger.bind( 'login', function() {
    2362                                 iframe.remove();
    2363                                 messenger.destroy();
    2364                                 delete previewer._login;
    2365                                 deferred.resolve();
     2361                        messenger.bind( 'login', function () {
     2362                                previewer.refreshNonces().done( function() {
     2363                                        iframe.remove();
     2364                                        messenger.destroy();
     2365                                        delete previewer._login;
     2366                                        deferred.resolve();
     2367                                });
    23662368                        });
    23672369
    23682370                        return this._login;
     
    23702372
    23712373                cheatin: function() {
    23722374                        $( document.body ).empty().addClass('cheatin').append( '<p>' + api.l10n.cheatin + '</p>' );
     2375                },
     2376
     2377                refreshNonces: function() {
     2378                        var self = this, request, deferred = $.Deferred();
     2379
     2380                        deferred.promise();
     2381
     2382                        request = wp.ajax.post( 'customize_refresh_nonces', {
     2383                                wp_customize: 'on',
     2384                                theme: api.settings.theme.stylesheet
     2385                        } );
     2386
     2387                        request.fail( function() {
     2388                                self.cheatin();
     2389                                deferred.reject();
     2390                        } );
     2391
     2392                        request.done( function( response ) {
     2393                                api.trigger( 'nonce-refresh', response );
     2394                                deferred.resolve();
     2395                        } );
     2396
     2397                        return deferred;
    23732398                }
    23742399        });
    23752400
     
    25382563                        $.extend( this.nonce, nonce );
    25392564                });
    25402565
     2566                // Refresh the nonces if login sends updated nonces over.
     2567                api.bind( 'nonce-refresh', function( nonce ) {
     2568                        $.extend( api.settings.nonce, nonce );
     2569                        $.extend( api.previewer.nonce, nonce );
     2570                });
     2571
    25412572                // Create Settings
    25422573                $.each( api.settings.settings, function( id, data ) {
    25432574                        api.create( id, id, data.value, {
  • src/wp-admin/js/customize-widgets.js

     
    18981898                sidebar_widgets: api.Widgets.SidebarControl
    18991899        });
    19001900
     1901        // Refresh the nonces if login sends updated nonces over.
     1902        api.bind( 'nonce-refresh', function( nonce ) {
     1903                api.Widgets.data.nonce = nonce['update-widget'];
     1904        });
     1905
    19011906        /**
    19021907         * Init Customizer for widgets.
    19031908         */
  • src/wp-includes/class-wp-customize-manager.php

     
    106106                remove_action( 'admin_init', '_maybe_update_themes' );
    107107
    108108                add_action( 'wp_ajax_customize_save', array( $this, 'save' ) );
     109                add_action( 'wp_ajax_customize_refresh_nonces', array( $this, 'refresh_nonces' ) );
    109110
    110111                add_action( 'customize_register',                 array( $this, 'register_controls' ) );
    111112                add_action( 'customize_register',                 array( $this, 'register_dynamic_settings' ), 11 ); // allow code to create settings first
     
    778779        }
    779780
    780781        /**
     782         * Refresh nonces for the current preview.
     783         *
     784         * @since 4.2.0
     785         */
     786        public function refresh_nonces() {
     787                if ( ! $this->is_preview() ) {
     788                        wp_send_json_error( 'not_preview' );
     789                }
     790
     791                $nonces = array(
     792                        'save'    => wp_create_nonce( 'save-customize_' . $this->get_stylesheet() ),
     793                        'preview' => wp_create_nonce( 'preview-customize_' . $this->get_stylesheet() ),
     794                );
     795
     796                /**
     797                 * Filter response data for a successful customize_refresh_nonces Ajax request.
     798                 *
     799                 * @since 4.2.0
     800                 *
     801                 * @param array                $nonces Array of new nonces for save an preview actions.
     802                 * @param WP_Customize_Manager $this   WP_Customize_Manager instance.
     803                 */
     804                $nonces = apply_filters( 'customize_refresh_nonces', $nonces, $this );
     805                wp_send_json_success( $nonces );
     806        }
     807
     808        /**
    781809         * Add a customize setting.
    782810         *
    783811         * @since 3.4.0
  • src/wp-includes/class-wp-customize-widgets.php

     
    9595                add_action( 'customize_controls_print_footer_scripts', array( $this, 'print_footer_scripts' ) );
    9696                add_action( 'customize_controls_print_footer_scripts', array( $this, 'output_widget_control_templates' ) );
    9797                add_action( 'customize_preview_init',                  array( $this, 'customize_preview_init' ) );
     98                add_filter( 'customize_refresh_nonces',                array( $this, 'refresh_nonces' ) );
    9899
    99100                add_action( 'dynamic_sidebar',                         array( $this, 'tally_rendered_widgets' ) );
    100101                add_filter( 'is_active_sidebar',                       array( $this, 'tally_sidebars_via_is_active_sidebar_calls' ), 10, 2 );
     
    887888        }
    888889
    889890        /**
     891         * Refresh nonce for widget updates.
     892         *
     893         * @since 4.2.0
     894         * @access public
     895         *
     896         * @param  array $nonces Array of nonces.
     897         * @return array $nonces Array of nonces.
     898         */
     899        public function refresh_nonces( $nonces ) {
     900                $nonces['update-widget'] = wp_create_nonce( 'update-widget' );
     901                return $nonces;
     902        }
     903
     904        /**
    890905         * When previewing, make sure the proper previewing widgets are used.
    891906         *
    892907         * Because wp_get_sidebars_widgets() gets called early at init