Opened 11 years ago
Closed 11 years ago
#27413 closed defect (bug) (fixed)
PHP warnings generated by wp_generate_tag_cloud
Reported by: | tomdxw | Owned by: | nacin |
---|---|---|---|
Milestone: | 3.9 | Priority: | normal |
Severity: | normal | Version: | 2.8 |
Component: | Taxonomy | Keywords: | has-patch |
Focuses: | Cc: |
Description (last modified by )
PHP Warning: min(): Array must contain at least one element in /var/vhost/xxxx/wp-includes/category-template.php on line 658
PHP Warning: max(): Array must contain at least one element in /var/vhost/xxxx/wp-includes/category-template.php on line 659
I'm not sure how to reproduce the bug but it can be fixed easily by replacing min( $counts )
with count( $counts ) > 0 ? min( $counts ) : 0
and replacing max( $counts )
with (count( $counts ) > 0 ? max( $counts ) : 0)
. Or by checking whether $counts is empty and returning early.
Attachments (2)
Change History (8)
#2
@
11 years ago
- Component changed from General to Taxonomy
- Description modified (diff)
- Keywords close added; dev-feedback needs-testing removed
Looks like the only way to trigger these warnings is to return an empty array in tag_cloud_sort
filter:
add_filter( 'tag_cloud_sort', '__return_empty_array' );
This looks like a developer error, so the developer should see the warning.
If the goal is to remove the output, wp_generate_tag_cloud
filter should be used instead:
tags/3.8.1/src/wp-includes/category-template.php#L694
#3
@
11 years ago
Yeah, that's true. This is the outcome of an unexpected behavior. Though I think, it should be handled because even the developers should not be put into confusion with such unwanted warnings/errors. Even if someone is passing an empty array; that should not affect the default workflow i.e., generate tag cloud if there are tags or do not generate tag cloud if empty array is passed
#4
@
11 years ago
- Keywords close removed
- Milestone changed from Awaiting Review to 3.9
- Version changed from 3.8.1 to 2.8
Introduced in [11037].
I guess we could check the filtered value and return if it's empty, see 27413.2.patch.
Also noticed that the function doesn't have a consistent return value, see #27487.
Added patch for the issue reported.
Review needed.
27413.patch