WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#36452 closed defect (bug) (fixed)

customize_value should be passed $this

Reported by: nwp_developer Owned by: westonruter
Milestone: 4.6 Priority: normal
Severity: normal Version: 4.4.2
Component: Customize Keywords: has-patch commit
Focuses: Cc:

Description

In $WP_Customize_Setting->value():

$value = apply_filters( "customize_value_{$id_base}", $value );

should be

$value = apply_filters( "customize_value_{$id_base}", $this);

because only having access to $default severely limits the ability to modify the value for custom settings not handled as theme_mod or option.

For example, if I need access to other setting properties at add_filter(customize_value...) to filter the setting value how do I get access to those properties?

Attachments (2)

36452.diff (956 bytes) - added by celloexpressions 3 years ago.
Pass $this to the customize_value_ filter.
36452.2.diff (4.9 KB) - added by westonruter 3 years ago.
Add unit tests

Download all attachments as: .zip

Change History (14)

@celloexpressions
3 years ago

Pass $this to the customize_value_ filter.

#1 @westonruter
3 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

You are absolutely right. See #29316 and review patch. I the mean time, I recommend using a WP_Customize_Setting subclass in lieu of using hooks to handle your custom setting type.

#2 @celloexpressions
3 years ago

  • Keywords has-patch added
  • Milestone set to Future Release
  • Type changed from feature request to defect (bug)

Good catch @nwp_developer!

I think this was an oversight when we started passing $this with all of the hooks here (hence marking as a bug). Every action and filter in WP_Customize_Setting passes $this as its last argument with this change; see 36452.diff. We do need to keep $value as the first argument for backwards compatibility, so a second parameter with the setting would be passed as well now. See previously #27979.

Per Slack discussion, let's see if we can get this smaller change in without waiting for a full resolution of the proposed new hooks in #29316.

#4 @netweb
3 years ago

  • Resolution duplicate deleted
  • Status changed from closed to reopened

#5 @celloexpressions
3 years ago

  • Milestone changed from Future Release to 4.6

36452.diff should be ready for commit.

#6 follow-up: @nwp_developer
3 years ago

Thanks!

Can anyone give me a start to how to use do_action( "customize_preview_{$this->type}", $this ) if I have a setting that's saved outside of wp_options?

How would I handle the customizer iframe preview similar to how get_theme_mod() works? I can't use transport=>postMessage since content is dynamic.

#7 in reply to: ↑ 6 @westonruter
3 years ago

Replying to nwp_developer:

Can anyone give me a start to how to use do_action( "customize_preview_{$this->type}", $this ) if I have a setting that's saved outside of wp_options?

How would I handle the customizer iframe preview similar to how get_theme_mod() works? I can't use transport=>postMessage since content is dynamic.

Please ask this question on the support forums or on the WordPress Dev Stack Exchange.

#8 @celloexpressions
3 years ago

  • Keywords commit added
  • Owner set to westonruter
  • Status changed from reopened to reviewing

This ticket was mentioned in Slack in #core-customize by westonruter. View the logs.


3 years ago

@westonruter
3 years ago

Add unit tests

#10 @westonruter
3 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 37350:

Customize: Pass WP_Customize_Setting instance as second argument to customize_value_{$id_base} filter.

Adds parity with setting instance being passed as second argument to customize_sanitize_{$id} and customize_sanitize_js_{$id}. Allows the actual ID of the (multidimensional) setting value being filtered to be inspected.

Props celloexpressions, westonruter.
Fixes #36452.

#11 @celloexpressions
3 years ago

  • Keywords needs-dev-note added

#12 @ocean90
3 years ago

  • Keywords needs-dev-note removed
Note: See TracTickets for help on using tickets.