[wp-trac] [WordPress Trac] #23089: Rewrite a confusing condition in default-widgets.php
WordPress Trac
noreply at wordpress.org
Thu Feb 28 18:40:43 UTC 2013
#23089: Rewrite a confusing condition in default-widgets.php
------------------------------+-----------------------
Reporter: alexvorn2 | Owner:
Type: enhancement | Status: reopened
Priority: lowest | Milestone: 3.6
Component: Widgets | Version:
Severity: minor | Resolution:
Keywords: has-patch commit |
------------------------------+-----------------------
Comment (by nacin):
The problem with something like `! empty( $instance['number'] ) ? absint(
$instance['number'] ) : 10` is if 'number' is malformed, it gets cast to
0, and that 0 never becomes a 5.
Something like this seems like it would be the most straightforward:
{{{
$title = ! empty( $instance['title'] ) ? $instance['title'] : __( 'Recent
Posts' );
$title = apply_filters( 'widget_title', $title, $instance, $this->id_base
);
$number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) :
10;
if ( ! $number )
$number = 10;
}}}
I also don't think this is too hard to read:
{{{
if ( empty( $instance['number'] ) || ! $number = absint(
$instance['number'] ) )
$number = 10;
}}}
Which happens to be exactly what we have now.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/23089#comment:14>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list