[wp-trac] [WordPress Trac] #45812: WP_Customize_Setting sanitize_callback is given 2 parameters; PHP warning and validation fail

WordPress Trac noreply at wordpress.org
Wed Jan 2 19:27:31 UTC 2019


#45812: WP_Customize_Setting sanitize_callback is given 2 parameters; PHP warning
and validation fail
--------------------------+------------------------------
 Reporter:  marclarr      |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Customize     |     Version:  3.4
 Severity:  normal        |  Resolution:
 Keywords:  close         |     Focuses:
--------------------------+------------------------------
Changes (by dlh):

 * keywords:   => close
 * version:  5.0.2 => 3.4


Comment:

 Welcome to Trac, @marclarr!

 `sanitize_hex_color()` and other user-defined functions support
 [http://php.net/manual/en/functions.arguments.php#functions.variable-arg-
 list variable argument lengths], but I don't believe that internal PHP
 functions do, hence the warning.

 Like @joyously, I'm not sure I see a bug here. It's a bit inconvenient to
 have to use the closure to call `floatval()`, but I think it's the only
 way to do so if passed as the `sanitize_callback` given that `floatval()`
 is an internal function.

 Alternatively, rather than passing `floatval` as a `sanitize_callback`,
 hook `floatval` into the dynamic `customize_sanitize_{$id}` filter in your
 own code and instruct the filter to pass only `1` argument instead of `2`.

 #34659 addresses a similar issue in the REST API. If an approach is found
 there, perhaps it could be adopted in the Customizer as well.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/45812#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list