[wp-trac] [WordPress Trac] #34140: Missing return values for WP_Customize_Setting::update( $value ) (was: WP_Customize_Setting::update( $value ) bad return value)
WordPress Trac
noreply at wordpress.org
Sun Oct 4 20:28:13 UTC 2015
#34140: Missing return values for WP_Customize_Setting::update( $value )
-------------------------+------------------
Reporter: wpweaver | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: 4.4
Component: Customize | Version: 3.4
Severity: normal | Resolution:
Keywords: has-patch | Focuses:
-------------------------+------------------
Changes (by westonruter):
* version: 4.3.1 => 3.4
* milestone: Awaiting Review => 4.4
* keywords: reporter-feedback => has-patch
* type: defect (bug) => enhancement
Old description:
> The update function seems to need to return a value to get the Save &
> Publish button to change to Saved (I'm guessing).
>
> At any rate, the default: case has:
>
> {{{
> return do_action( 'customize_update_' . $this->type, $value, $this );
> }}}
>
> The problem is that do_action does not return a value. This failure makes
> it impossible to save options with a custom setting type using preview.
> And as noted in another ticket, preview is seriously broken with the
> order(N(squared)) issue.
New description:
The docs for `WP_Customize_Setting::update()` method indicate it returns a
value for “The result of saving the value.” For custom types (non-option
or theme_mod) it will return via:
{{{
return do_action( 'customize_update_' . $this->type, $value, $this );
}}}
The problem is that `do_action()` does not return a value.
--
Comment:
The reality is that the return value for `WP_Customize_Setting::update()`
(a protected method) value is not even used in Core. As I can see, it is
only used in `WP_Customize_Setting::save()` and is called as:
{{{
$this->update( $value );
}}}
So its return value is not used. The `WP_Customize_Setting::save()` method
is called via `WP_Customize_Manager::save()`:
{{{
foreach ( $this->settings as $setting ) {
$setting->save();
}
}}}
The `@return` tag for the `update()` method says that the return value is
supposed to be “The result of saving the value.” Currently this only
returns a value (other than `null`/void) when it calls
`WP_Customize_Setting::_update_option()`, since it ''does'' return a
value. But `WP_Customize_Setting::_update_theme_mod()` does not return a
value, and for custom types, calling `do_action()` also does not return a
value.
In the latter case, it can just be changed to return whether there was was
any callback added for that action to begin with.
See [attachment:34140.diff].
--
Ticket URL: <https://core.trac.wordpress.org/ticket/34140#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list