[wp-trac] [WordPress Trac] #38133: Core widget fields fail to render value of "0" when empty() checks are used (was: Default widget title used if instance title is "0")

WordPress Trac noreply at wordpress.org
Thu Sep 22 20:26:39 UTC 2016


#38133: Core widget fields fail to render value of "0" when empty() checks are used
---------------------------+-----------------------------
 Reporter:  hardeepasrani  |       Owner:
     Type:  defect (bug)   |      Status:  new
 Priority:  normal         |   Milestone:  Future Release
Component:  Widgets        |     Version:  2.6
 Severity:  normal         |  Resolution:
 Keywords:  needs-patch    |     Focuses:  administration
---------------------------+-----------------------------
Description changed by westonruter:

Old description:

> If you put a single zero 0 as the title in default widgets, it won't
> output any thing. You can try putting a 0 in any widget title or content.
> It works if you put 00 or anything else.
>
> The reason being our use of `empty( $variable )` and `! empty( $variable
> )` in the default widgets. `empty` returns FALSE if var exists and has a
> non-empty, non-zero value.
>
> So it will be better to use `isset( $variable) && $variable != ''`
> instead. Wanted to submit a patch but wanted to know if above method will
> be the best one.

New description:

 If you put a single zero 0 the instance property for in many default
 widgets, it won't output any thing if an `empty()` check is used since
 `empty( '0' ) === true`. You can try putting a 0 in any widget title or
 content. It works if you put 00 or anything else.

 The reason being our use of `empty( $variable )` and `! empty( $variable
 )` in the default widgets. `empty` returns FALSE if var exists and has a
 non-empty, non-zero value.

 So it will be better to use `isset( $variable) && $variable != ''`
 instead. Wanted to submit a patch but wanted to know if above method will
 be the best one.

--

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


More information about the wp-trac mailing list