[wp-trac] [WordPress Trac] #44162: Add is_countable() check to wp-admin/edit-form-advanced.php
WordPress Trac
noreply at wordpress.org
Sun May 20 20:21:43 UTC 2018
#44162: Add is_countable() check to wp-admin/edit-form-advanced.php
--------------------------+---------------------
Reporter: thrijith | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: 4.9.7
Component: General | Version: trunk
Severity: normal | Resolution:
Keywords: | Focuses:
--------------------------+---------------------
Comment (by birgire):
Replying to [comment:2 thrijith]:
> I am having a doubt regarding this, how to replace where count's value
is used directly?
> for eg
>
> {{{
>
> if ( is_array( $done ) ) {
> $done['updated'] = count( $done['updated'] );
> $done['skipped'] = count( $done['skipped'] );
> $done['locked'] = count( $done['locked'] );
> $sendback = add_query_arg( $done, $sendback );
> }
> }}}
Instead of this verbose way:
{{{
if ( is_array( $done ) ) {
$done['updated'] = is_countable( $done['updated'] ) ? count(
$done['updated'] ) : 0;
$done['skipped'] = is_countable( $done['skipped'] ) ? count(
$done['skipped'] ) : 0;
$done['locked'] = is_countable( $done['locked'] ) ? count(
$done['locked'] ) : 0;
$sendback = add_query_arg( $done, $sendback );
}
}}}
this comes to mind:
{{{
if ( is_array( $done ) ) {
foreach( array( 'update', 'skipped', 'locked' ) as $key ) {
$done[ $key ] = is_countable( $done[ $key ] ) ? count( $done[ $key
] ) : 0;
}
$sendback = add_query_arg( $done, $sendback );
}
}}}
but I've not tested this.
Personally I might even check if {{{$done[$key]}}} is set and use e.g. the
approach of adjusting an initial counting array {{{array( 'update' => 0,
'skipped' => 0, 'locked' => 0 )}}}, but I don't think we should make such
changes in the logic here, just keep it as simple as possible.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/44162#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list