#33366 closed defect (bug) (invalid)
if (get_theme_mod()) returns false if 0
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.2.4 |
Component: | Customize | Keywords: | |
Focuses: | Cc: |
Description
Seems like the number type isn't returning 0 in the customizer
Here's my control code in functions.php
$wp_customize->add_setting('apw_header_cta_padding_bottom', array( 'default' => '20' ) ); $wp_customize->add_control( new Customize_Number_Control( $wp_customize, 'header_cta_padding_bottom', array( 'label' => 'Bottom Padding', 'section' => 'apw_header_cta', 'settings' => 'apw_header_cta_padding_bottom', 'type' => 'number', 'priority' => 30 ) ) );
Then, in my header.php I have
<?php if(get_theme_mod( 'apw_header_cta_padding_bottom')) : ?>
Then, when I preview the site in the customizer and set that value to zero, this if statement returns false when the value should be zero.
Change History (4)
#1
follow-up:
↓ 2
@
10 years ago
- Milestone Awaiting Review deleted
- Resolution set to invalid
- Status changed from new to closed
#2
in reply to:
↑ 1
@
10 years ago
oh whoops! You're right. That did work :)
Really appreciate your help!!!
Replying to westonruter:
@karlikdesign: Thanks for the report. Actually this is not a bug because in PHP the value of
0
is “false-y”. You can see the values in PHP that are consideredfalse
in a boolean context via the PHP Manual.
So all you have to do is change your conditional to check for the
false
value explicitly with a not-identical comparison:
<?php if ( false !== get_theme_mod( 'apw_header_cta_padding_bottom' ) ) : ?>You probably want to report such future issues to the WordPress Support forums first before opening a Core Trac ticket. Thanks!
@karlikdesign: Thanks for the report. Actually this is not a bug because in PHP the value of
0
is “false-y”. You can see the values in PHP that are consideredfalse
in a boolean context via the PHP Manual.So all you have to do is change your conditional to check for the
false
value explicitly with a not-identical comparison:You probably want to report such future issues to the WordPress Support forums first before opening a Core Trac ticket. Thanks!