[wp-trac] [WordPress Trac] #33499: Allow `$autoload` to be set in `WP_Customize_Setting::_update_option()`
WordPress Trac
noreply at wordpress.org
Fri Aug 21 21:19:37 UTC 2015
#33499: Allow `$autoload` to be set in `WP_Customize_Setting::_update_option()`
-------------------------------+------------------------------
Reporter: dlh | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Customize | Version:
Severity: normal | Resolution:
Keywords: reporter-feedback | Focuses:
-------------------------------+------------------------------
Changes (by westonruter):
* keywords: => reporter-feedback
Comment:
Instead of adding a new filter, what about just subclassing
`WP_Customize_Setting` in your plugin? For instance:
{{{#!php
<?php
class Non_Autoloaded_Option_Customize_Setting extends WP_Customize_Setting
{
public $type = 'non_autoloaded_option';
/**
* Update the non-autoloaded option from the value of the setting.
*
* @param mixed $value The value to update.
* @return bool The result of saving the value.
*/
protected function _update_option( $value ) {
$autoload = false;
// Handle non-array option.
if ( empty( $this->id_data['keys'] ) ) {
return update_option( $this->id_data['base'],
$value, $autoload );
}
// Handle array-based options.
$options = get_option( $this->id_data['base'] );
$options = $this->multidimensional_replace( $options,
$this->id_data['keys'], $value );
if ( isset( $options ) ) {
return update_option( $this->id_data['base'],
$options, $autoload );
}
}
}
}}}
And then use it by explicitly constructing the setting object when calling
`WP_Customize_Manager::add_setting()`:
{{{#!php
<?php
add_action( 'customize_register', function ( $wp_customize ) {
/** @var WP_Customize_Manager $wp_customize */
$wp_customize->add_setting( new
Non_Autoloaded_Option_Customize_Setting( $wp_customize, 'foo' ));
$wp_customize->add_control( 'foo', array( /* ... */ ) )
} );
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/33499#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list