Make WordPress Core


Ignore:
Timestamp:
04/30/2012 03:46:17 PM (15 years ago)
Author:
koopersmith
Message:

Theme Customizer: Migrate to an ajax-based solution for refreshing the preview and saving. see #20507, #19910.

  • Use ajax-based saving, add saving indicator.
  • Use ajax-based refreshing instead of form targets.
  • Instead of using hidden inputs with prefixed names to track the canonical data, use the values stored in wp.customize. Encode the values as JSON before sending to avoid bugs with ids that contain square brackets (PHP mangles POST values with nested brackets).
  • Use wp.customize.Previewer solely for the purpose of previewing; move the postMessage connection with the parent frame and other unrelated code snippets into the 'ready' handler.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/class-wp-customize.php

    r20598 r20645  
    1818        protected $controls = array();
    1919
     20        protected $customized;
     21
     22        private $_post_values;
     23
    2024        /**
    2125         * Constructor.
    … …  
    3135                add_action( 'admin_init',   array( $this, 'admin_init' ) );
    3236                add_action( 'wp_loaded',    array( $this, 'wp_loaded' ) );
     37
     38                add_action( 'wp_ajax_customize_save', array( $this, 'save' ) );
    3339
    3440                add_action( 'customize_register',                 array( $this, 'register_controls' ) );
    … …  
    150156
    151157        /**
     158         * Decode the $_POST attribute used to override the WP_Customize_Setting values.
     159         *
     160         * @since 3.4.0
     161         */
     162        public function post_value( $setting ) {
     163                if ( ! isset( $this->_post_values ) ) {
     164                        if ( isset( $_POST['customized'] ) )
     165                                $this->_post_values = json_decode( stripslashes( $_POST['customized'] ), true );
     166                        else
     167                                $this->_post_values = false;
     168                }
     169
     170                if ( isset( $this->_post_values[ $setting->id ] ) )
     171                        return $setting->sanitize( $this->_post_values[ $setting->id ] );
     172        }
     173
     174
     175        /**
    152176         * Print javascript settings.
    153177         *
    … …  
    268292         */
    269293        public function admin_init() {
    270                 if ( isset( $_REQUEST['save_customize_controls'] ) )
    271                         $this->save();
    272 
    273294                if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) )
    274295                        return;
    … …  
    298319        public function save() {
    299320                if ( ! $this->is_preview() )
    300                         return;
    301 
    302                 check_admin_referer( 'customize_controls' );
     321                        die;
     322
     323                check_ajax_referer( 'customize_controls', 'nonce' );
    303324
    304325                // Do we have to switch themes?
    305326                if ( $this->get_stylesheet() != $this->original_stylesheet ) {
    306327                        if ( ! current_user_can( 'switch_themes' ) )
    307                                 return;
     328                                die;
    308329
    309330                        // Temporarily stop previewing the theme to allow switch_themes()
    … …  
    321342
    322343                add_action( 'admin_notices', array( $this, '_save_feedback' ) );
     344
     345                die;
    323346        }
    324347
Note: See TracChangeset for help on using the changeset viewer.