[wp-trac] [WordPress Trac] #44168: Add is_countable() check to wp-admin/includes/ajax-actions.php

WordPress Trac noreply at wordpress.org
Mon May 21 06:56:47 UTC 2018


#44168: Add is_countable() check to wp-admin/includes/ajax-actions.php
-----------------------------------------+------------------------------
 Reporter:  thrijith                     |       Owner:  (none)
     Type:  defect (bug)                 |      Status:  new
 Priority:  normal                       |   Milestone:  Awaiting Review
Component:  General                      |     Version:  trunk
 Severity:  normal                       |  Resolution:
 Keywords:  has-patch reporter-feedback  |     Focuses:
-----------------------------------------+------------------------------
Changes (by subrataemfluence):

 * keywords:  has-patch => has-patch reporter-feedback


Comment:

 Thanks for the ticket and patch you have proposed.

 Code snippet 1:

 {{{#!php
 <?php
 if ( is_taxonomy_hierarchical( $taxonomy ) ) {
    $level = count( get_ancestors( $tag->term_id, $taxonomy, 'taxonomy' )
 );
    $ancestors = get_ancestors( $tag->term_id, $taxonomy, 'taxonomy' );
    $level     = is_countable( $ancestors ) ? count( $ancestors ) : 0;
    ...
 }
 }}}


 I don't think `is_countable()` is necessary here since the return value of
 `is_taxonomy_hierarchical()` is either `true` or `false`. If it is true,
 and since get_ancestors() always returns an array(), we can safely use
 count() on get_ancestors(). Otherwise, this block will not execute.

 Code snippet 2:

 {{{#!php
 <?php
 $status['count'] = count( $wp_list_table->items );
 $status['count'] = is_countable( $wp_list_table->items ) ? count(
 $wp_list_table->items ) : 0;
 }}}


 Hence, `$wp_list_table->items` always returns an array, I think use of
 `is_countable()` will create over burden.

 Here is the definition of `$items` in `class-wp-list-table.php`

 {{{#!php
 <?php
 /**
 * The current list of items.
 *
 * @since 3.1.0
 * @var array
 */
 public $items;
 }}}


 Code snippet 3:

 {{{#!php
 <?php
 if ( is_countable( $exporters ) && 0 < count( $exporters ) ) { ... }
 }}}


 This is how we get $exporters. The value is already set as array().
 {{{#!php
 <?php
 $exporters = apply_filters( 'wp_privacy_personal_data_exporters', array()
 );
 }}}


 so, I believe we can safely use `count()` directly on `$exporters`.

 Code snippet 4:

 {{{#!php
 <?php
 $erasers = apply_filters( 'wp_privacy_personal_data_erasers', array() );
 }}}


 Same as above.

 Please let me know your views on this.

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


More information about the wp-trac mailing list