Make WordPress Core

Ticket #29098: 29098.2.diff

File 29098.2.diff, 3.0 KB (added by westonruter, 12 years ago)

https://github.com/xwp/wordpress-develop/compare/325eb80...807c992 PR: https://github.com/xwp/wordpress-develop/pull/27

  • src/wp-admin/js/customize-controls.js

    diff --git src/wp-admin/js/customize-controls.js src/wp-admin/js/customize-controls.js
    index f43630a..7c4a631 100644
     
    19451945                        save: function() {
    19461946                                var self  = this,
    19471947                                        query = $.extend( this.query(), {
    1948                                                 action: 'customize_save',
    19491948                                                nonce:  this.nonce.save
    19501949                                        } ),
    19511950                                        processing = api.state( 'processing' ),
     
    19551954                                body.addClass( 'saving' );
    19561955
    19571956                                submit = function () {
    1958                                         var request = $.post( api.settings.url.ajax, query );
     1957                                        var request = wp.ajax.post( 'customize_save', query );
    19591958
    19601959                                        api.trigger( 'save', request );
    19611960
     
    19631962                                                body.removeClass( 'saving' );
    19641963                                        } );
    19651964
    1966                                         request.done( function( response ) {
    1967                                                 // Check if the user is logged out.
     1965                                        request.fail( function ( response ) {
    19681966                                                if ( '0' === response ) {
     1967                                                        response = 'not_logged_in';
     1968                                                } else if ( '-1' === response ) {
     1969                                                        // Back-compat in case any other check_ajax_referer() call is dying
     1970                                                        response = 'invalid_nonce';
     1971                                                }
     1972
     1973                                                if ( 'invalid_nonce' === response ) {
     1974                                                        self.cheatin();
     1975                                                } else if ( 'not_logged_in' === response ) {
    19691976                                                        self.preview.iframe.hide();
    19701977                                                        self.login().done( function() {
    19711978                                                                self.save();
    19721979                                                                self.preview.iframe.show();
    19731980                                                        } );
    1974                                                         return;
    1975                                                 }
    1976 
    1977                                                 // Check for cheaters.
    1978                                                 if ( '-1' === response ) {
    1979                                                         self.cheatin();
    1980                                                         return;
    19811981                                                }
     1982                                                api.trigger( 'error', response );
     1983                                        } );
    19821984
     1985                                        request.done( function( response ) {
    19831986                                                // Clear setting dirty states
    19841987                                                api.each( function ( value ) {
    19851988                                                        value._dirty = false;
    19861989                                                } );
    1987                                                 api.trigger( 'saved' );
     1990
     1991                                                api.trigger( 'saved', response );
    19881992                                        } );
    19891993                                };
    19901994
  • src/wp-includes/class-wp-customize-manager.php

    diff --git src/wp-includes/class-wp-customize-manager.php src/wp-includes/class-wp-customize-manager.php
    index 60303e6..58e8c0f 100644
    final class WP_Customize_Manager {  
    628628         * @since 3.4.0
    629629         */
    630630        public function save() {
    631                 if ( ! $this->is_preview() )
    632                         die;
     631                if ( ! $this->is_preview() ) {
     632                        wp_send_json_error( 'not_preview' );
     633                }
    633634
    634                 check_ajax_referer( 'save-customize_' . $this->get_stylesheet(), 'nonce' );
     635                $action = 'save-customize_' . $this->get_stylesheet();
     636                if ( ! check_ajax_referer( $action, 'nonce', false ) ) {
     637                        wp_send_json_error( 'invalid_nonce' );
     638                }
    635639
    636640                // Do we have to switch themes?
    637641                if ( ! $this->is_theme_active() ) {
    final class WP_Customize_Manager {  
    666670                 */
    667671                do_action( 'customize_save_after', $this );
    668672
    669                 die;
     673                /**
     674                 * Filter response data for customize_save Ajax request.
     675                 *
     676                 * @since 4.2.0
     677                 *
     678                 * @param array $data
     679                 * @param WP_Customize_Manager $this WP_Customize_Manager instance.
     680                 */
     681                $response = apply_filters( 'wp_customize_save_response', array(), $this );
     682                wp_send_json_success( $response );
    670683        }
    671684
    672685        /**