mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 12:20:22 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@20645 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -17,6 +17,10 @@ final class WP_Customize {
|
||||
protected $sections = array();
|
||||
protected $controls = array();
|
||||
|
||||
protected $customized;
|
||||
|
||||
private $_post_values;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
@@ -31,6 +35,8 @@ final class WP_Customize {
|
||||
add_action( 'admin_init', array( $this, 'admin_init' ) );
|
||||
add_action( 'wp_loaded', array( $this, 'wp_loaded' ) );
|
||||
|
||||
add_action( 'wp_ajax_customize_save', array( $this, 'save' ) );
|
||||
|
||||
add_action( 'customize_register', array( $this, 'register_controls' ) );
|
||||
add_action( 'customize_controls_init', array( $this, 'prepare_controls' ) );
|
||||
add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_control_scripts' ) );
|
||||
@@ -148,6 +154,24 @@ final class WP_Customize {
|
||||
$this->customize_preview_init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the $_POST attribute used to override the WP_Customize_Setting values.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*/
|
||||
public function post_value( $setting ) {
|
||||
if ( ! isset( $this->_post_values ) ) {
|
||||
if ( isset( $_POST['customized'] ) )
|
||||
$this->_post_values = json_decode( stripslashes( $_POST['customized'] ), true );
|
||||
else
|
||||
$this->_post_values = false;
|
||||
}
|
||||
|
||||
if ( isset( $this->_post_values[ $setting->id ] ) )
|
||||
return $setting->sanitize( $this->_post_values[ $setting->id ] );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Print javascript settings.
|
||||
*
|
||||
@@ -267,9 +291,6 @@ final class WP_Customize {
|
||||
* @since 3.4.0
|
||||
*/
|
||||
public function admin_init() {
|
||||
if ( isset( $_REQUEST['save_customize_controls'] ) )
|
||||
$this->save();
|
||||
|
||||
if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) )
|
||||
return;
|
||||
|
||||
@@ -297,14 +318,14 @@ final class WP_Customize {
|
||||
*/
|
||||
public function save() {
|
||||
if ( ! $this->is_preview() )
|
||||
return;
|
||||
die;
|
||||
|
||||
check_admin_referer( 'customize_controls' );
|
||||
check_ajax_referer( 'customize_controls', 'nonce' );
|
||||
|
||||
// Do we have to switch themes?
|
||||
if ( $this->get_stylesheet() != $this->original_stylesheet ) {
|
||||
if ( ! current_user_can( 'switch_themes' ) )
|
||||
return;
|
||||
die;
|
||||
|
||||
// Temporarily stop previewing the theme to allow switch_themes()
|
||||
// to operate properly.
|
||||
@@ -320,6 +341,8 @@ final class WP_Customize {
|
||||
}
|
||||
|
||||
add_action( 'admin_notices', array( $this, '_save_feedback' ) );
|
||||
|
||||
die;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user