Opened 7 years ago
Closed 6 years ago
#44168 closed defect (bug) (wontfix)
Add is_countable() check to wp-admin/includes/ajax-actions.php
Reported by: | thrijith | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Administration | Keywords: | has-patch 2nd-opinion |
Focuses: | administration | Cc: |
Description
Update code with is_countable()
wherever necessary in wp-admin/includes/ajax-actions.php
See #44123.
Attachments (1)
Change History (6)
#3
@
7 years ago
- Focuses administration added
- Keywords close added; reporter-feedback removed
- Version trunk deleted
Thanks for your work on this, @thrijith!
I do not think that is_countable()
is needed for any of these instances of count()
, though. is_countable()
should only be used before counting a value where it's valid for either a countable or non-countable value to be passed (see 44123#comment:11).
- While it is possible for the
get_ancestors()
function to return an uncountable value if a plugin or theme incorrectly uses theget_ancestors
filter, this would be a bug. $wp_list_table->items
could also not be countable. But this also indicates a bug in the list table class being used.- The third example is already preceded by a
! is_array()
check and would never be reached if the$exporters
variable is not countable. - If a plugin or theme is incorrectly using the
wp_privacy_personal_data_erasers
filter, this is a bug and the warning should not be suppressed.
Note: See
TracTickets for help on using
tickets.
Thanks for the ticket and patch you have proposed.
Code snippet 1:
I don't think
is_countable()
is necessary here since the return value ofis_taxonomy_hierarchical()
is eithertrue
orfalse
. 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:
Hence,
$wp_list_table->items
always returns an array, I think use ofis_countable()
will create over burden.Here is the definition of
$items
inclass-wp-list-table.php
Code snippet 3:
This is how we get $exporters. The value is already set as array().
so, I believe we can safely use
count()
directly on$exporters
.Code snippet 4:
Same as above.
Please let me know your views on this.