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:
Dominik Schilling (ocean90)
2015-02-03 10:14:28 +00:00
parent 5811dcbcd6
commit 8bc9ad756d
4 changed files with 503 additions and 21 deletions
+24 -3
View File
@@ -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;