[wp-trac] [WordPress Trac] #33366: if (get_theme_mod()) returns false if 0

WordPress Trac noreply at wordpress.org
Thu Aug 13 18:03:24 UTC 2015


#33366: if (get_theme_mod()) returns false if 0
--------------------------+----------------------
 Reporter:  karlikdesign  |       Owner:
     Type:  defect (bug)  |      Status:  closed
 Priority:  normal        |   Milestone:
Component:  Customize     |     Version:  4.2.4
 Severity:  normal        |  Resolution:  invalid
 Keywords:                |     Focuses:
--------------------------+----------------------
Changes (by westonruter):

 * status:  new => closed
 * resolution:   => invalid
 * milestone:  Awaiting Review =>


Comment:

 @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 considered `false` in a boolean context via the
 [http://php.net/manual/en/language.types.boolean.php#language.types.boolean.casting
 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
 <?php if ( false !== get_theme_mod( 'apw_header_cta_padding_bottom' ) ) :
 ?>
 }}}

 You probably want to report such future issues to the
 [https://wordpress.org/support/ WordPress Support forums] first before
 opening a Core Trac ticket. Thanks!

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


More information about the wp-trac mailing list