Make WordPress Core

Opened 12 years ago

Closed 9 years ago

#21918 closed defect (bug) (invalid)

WP_Customize_Control() doesn't work with add_setting() default theme_mod type

Reported by: sebstyle's profile sebstyle Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.4.2
Component: Customize Keywords: reporter-feedback close
Focuses: Cc:

Description

Consider the following code:

            $wp_customize->add_setting($color,array(
                    'default'           => '#000000',
                    'sanitize_callback' => 'sanitize_hex_color',
                    'capability'        => 'edit_theme_options',
                    'transport'         => 'postMessage'
                )
            );
            $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize,$color,array(
                        'label'         => 'somelabel',
                        'section'       => 'colors'
                    )
                )
            );

The default 'type' used for add_setting() is 'theme_mod' as defined in http://codex.wordpress.org/Class_Reference%5CWP_Customize_Manager%5Cadd_setting

The WP_Customize_Color_Control does not accept the 'default' setting when there is no 'type' specified.

The WP_Customize_Color_Control does accept the 'default' setting when 'type' is either set to 'option' or 'theme_mods'.

Setting it to 'option' makes no sense because that would imply that one would be using a custom option database field with get_option() instead of the default database field used by get_theme_mod().

Because setting it to 'theme_mods' works and 'theme_mod' does not i suggest checking code for typos.

Expected behavior would be for it to work with theme_mod/get_theme_mod stored values when the default 'type' is used.

Change History (7)

#1 @scribu
12 years ago

  • Milestone changed from Awaiting Review to 3.5

#2 @scribu
12 years ago

  • Keywords reporter-feedback added; needs-testing needs-patch removed
  • Milestone changed from 3.5 to Awaiting Review

I pasted that exact code and it works as expected (get black as the default color) in WP 3.5-alpha.

#3 follow-up: @scribu
12 years ago

Note that once you set a color through the UI, there is no way to clear it, so that you get the default value again.

To test the default, you either need to remove the color via some code or change the $color variable.

#4 in reply to: ↑ 3 @SergeyBiryukov
12 years ago

Replying to scribu:

Note that once you set a color through the UI, there is no way to clear it, so that you get the default value again.

Related: #21059

#5 @nacin
11 years ago

  • Component changed from Themes to Appearance

#6 @celloexpressions
10 years ago

  • Keywords close added

I've never seen any issues like this, and if there is still an issue here it would be specific to the color control.

#7 @wonderboymusic
9 years ago

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

comment:6 calls it invalid 12 months ago - thanks for the ticket, though. Let us know if there's anything else you find in the future, we'll be happy to take a look.

Note: See TracTickets for help on using tickets.