[wp-trac] [WordPress Trac] #26817: WP_Customize_Setting default value set to empty string by default

WordPress Trac noreply at wordpress.org
Sun Jan 12 14:06:44 UTC 2014


#26817: WP_Customize_Setting default value set to empty string by default
-------------------------+-----------------------------
 Reporter:  bassjobsen   |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Database     |    Version:  3.8
 Severity:  normal       |   Keywords:
-------------------------+-----------------------------
 class-wp-customize-setting.php

 Sets `$default` to an empty string. I think this should be `null` or
 `false`.

 This empty string requires to set the value of `default`  explicit to
 `false` always when use customizer's `add_setting()`. In the cases you
 don't want to set the default value.

 Example use case:

 I want to create a customizable color setting and in my code i will set an
 alternative code if color is not set.

 So i use `$wp_customize->add_setting('color',array())`, although it
 doesn't throw an errors, docs tell me the setting array is required? (see:
 http://codex.wordpress.org/Class_Reference/WP_Customize_Manager/add_setting).

 Now in my code i try to use:
 get_theme_option('color','green');

 Note i expect my color become green unless the user sets it to some
 different value via the customizer.

 The above won't work cause `get_theme_option('color','green');` returns an
 empty string instead of green.

 The above can also be solved
 `$wp_customize->add_setting('color',array('default'=>false))` but defining
 a default as false if i don't need a default doesn't feel solid.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/26817>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list