Customizer: Introduce an API to create WP_Customize_Settings for dynamically-created settings.

* Introduce WP_Customize_Manager::add_dynamic_settings() to register dynamically-created settings.
* Introduce `customize_dynamic_setting_args` filter to pass an array of args to a dynamic setting's constructor.
* Add unit tests for WP_Customize_Manager and WP_Customize_Widgets.
* See WP_Customize_Widgets as an example.

props westonruter.
fixes #30936.

git-svn-id: https://develop.svn.wordpress.org/trunk@31370 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dominik Schilling (ocean90)
2015-02-08 23:10:05 +00:00
parent 76b84b9231
commit 2518bbbb1f
5 changed files with 607 additions and 273 deletions

View File

@@ -54,14 +54,6 @@ class WP_Customize_Setting {
protected $id_data = array();
/**
* Cached and sanitized $_POST value for the setting.
*
* @access private
* @var mixed
*/
private $_post_value;
/**
* Constructor.
*
@@ -163,7 +155,7 @@ class WP_Customize_Setting {
*/
public function _preview_filter( $original ) {
$undefined = new stdClass(); // symbol hack
$post_value = $this->manager->post_value( $this, $undefined );
$post_value = $this->post_value( $undefined );
if ( $undefined === $post_value ) {
$value = $this->_original_value;
} else {
@@ -211,17 +203,7 @@ class WP_Customize_Setting {
* @return mixed The default value on failure, otherwise the sanitized value.
*/
final public function post_value( $default = null ) {
// Check for a cached value
if ( isset( $this->_post_value ) )
return $this->_post_value;
// Call the manager for the post value
$result = $this->manager->post_value( $this );
if ( isset( $result ) )
return $this->_post_value = $result;
else
return $default;
return $this->manager->post_value( $this, $default );
}
/**