mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 12:20:22 +00:00
Ensure that WP_Customize_Setting::value() returns default value for setting if not dirty.
There was regression introduced by #28580 where only changed (dirty) settings now are POST'ed to the Customizer preview. * Allow WP_Customize_Manager::post_value() to accept a second $default argument. * Introduce WP_Customize_Manager::unsanitized_post_values() for accessing previously-private member variable _post_values. * Do require_once instead of require for Customizer classes. * Add unit tests for WP_Customize_Manager and WP_Customize_Setting. props westonruter. fixes #30988. git-svn-id: https://develop.svn.wordpress.org/trunk@31329 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -100,12 +100,18 @@ class WP_Customize_Setting {
|
||||
add_filter( "customize_sanitize_js_{$this->id}", $this->sanitize_js_callback, 10, 2 );
|
||||
}
|
||||
|
||||
protected $_original_value;
|
||||
|
||||
/**
|
||||
* Handle previewing the setting.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*/
|
||||
public function preview() {
|
||||
if ( ! isset( $this->_original_value ) ) {
|
||||
$this->_original_value = $this->value();
|
||||
}
|
||||
|
||||
switch( $this->type ) {
|
||||
case 'theme_mod' :
|
||||
add_filter( 'theme_mod_' . $this->id_data[ 'base' ], array( $this, '_preview_filter' ) );
|
||||
@@ -156,7 +162,15 @@ class WP_Customize_Setting {
|
||||
* @return mixed New or old value.
|
||||
*/
|
||||
public function _preview_filter( $original ) {
|
||||
return $this->multidimensional_replace( $original, $this->id_data[ 'keys' ], $this->post_value() );
|
||||
$undefined = new stdClass(); // symbol hack
|
||||
$post_value = $this->manager->post_value( $this, $undefined );
|
||||
if ( $undefined === $post_value ) {
|
||||
$value = $this->_original_value;
|
||||
} else {
|
||||
$value = $post_value;
|
||||
}
|
||||
|
||||
return $this->multidimensional_replace( $original, $this->id_data['keys'], $value );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -422,8 +436,15 @@ class WP_Customize_Setting {
|
||||
$node = &$node[ $key ];
|
||||
}
|
||||
|
||||
if ( $create && ! isset( $node[ $last ] ) )
|
||||
$node[ $last ] = array();
|
||||
if ( $create ) {
|
||||
if ( ! is_array( $node ) ) {
|
||||
// account for an array overriding a string or object value
|
||||
$node = array();
|
||||
}
|
||||
if ( ! isset( $node[ $last ] ) ) {
|
||||
$node[ $last ] = array();
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! isset( $node[ $last ] ) )
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user