Opened 21 months ago
Closed 8 months ago
#44168 closed defect (bug) (wontfix)
Add is_countable() check to wp-admin/includes/ajax-actions.php
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | |
| Component: | Administration | Keywords: | has-patch 2nd-opinion |
| Focuses: | administration | Cc: | |
| PR Number: |
Description
Update code with is_countable() wherever necessary in wp-admin/includes/ajax-actions.php
See #44123.
Attachments (1)
Change History (6)
#3
@
21 months 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_ancestorsfilter, this would be a bug. $wp_list_table->itemscould 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$exportersvariable is not countable. - If a plugin or theme is incorrectly using the
wp_privacy_personal_data_erasersfilter, 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 eithertrueorfalse. 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->itemsalways returns an array, I think use ofis_countable()will create over burden.Here is the definition of
$itemsinclass-wp-list-table.phpCode 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.