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

WordPress Trac noreply at wordpress.org
Thu Sep 22 22:23:42 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
---------------------------+-----------------------------

Comment (by SergeyBiryukov):

 [attachment:widgets.diff] is a great start.

 * While we're at it, it would be great to replace cryptic lines like this:
  {{{
 /** This filter is documented in wp-includes/widgets/class-wp-widget-
 pages.php */
 $title = apply_filters( 'widget_title', isset( $instance['title'] ) &&
 $instance['title'] !== '' ? $instance['title'] : '', $instance,
 $this->id_base );
 }}}
  with this:
  {{{
 if ( isset( $instance['title'] ) && '' !== $instance['title'] ) {
         $title = $instance['title'];
 } else {
         $title = '';
 }

 /** This filter is documented in wp-includes/widgets/class-wp-widget-
 pages.php */
 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base
 );
 }}}
  for clarity. See #23089.
 * `isset($instance['title'])` should be `isset( $instance['title'] )`, see
 [https://make.wordpress.org/core/handbook/best-practices/coding-
 standards/php/#brace-style Brace Style].
 * `$instance['title'] !== ''` should be `'' !== $instance['title']`, see
 [https://make.wordpress.org/core/handbook/best-practices/coding-
 standards/php/#yoda-conditions Yoda Conditions].
 * It probably makes sense to check if `$instance['title']` is set (just in
 case, although it should always be set anyway), but `isset( $title )`
 would be redundant, as it's always set just a few lines above.

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


More information about the wp-trac mailing list