[wp-trac] [WordPress Trac] #27413: PHP warnings generated by wp_generate_tag_cloud

WordPress Trac noreply at wordpress.org
Fri Mar 21 14:29:44 UTC 2014


#27413: PHP warnings generated by wp_generate_tag_cloud
-----------------------------+------------------------------
 Reporter:  tomdxw           |       Owner:
     Type:  defect (bug)     |      Status:  new
 Priority:  normal           |   Milestone:  Awaiting Review
Component:  Taxonomy         |     Version:  3.8.1
 Severity:  normal           |  Resolution:
 Keywords:  has-patch close  |     Focuses:
-----------------------------+------------------------------
Changes (by SergeyBiryukov):

 * keywords:  has-patch dev-feedback needs-testing => has-patch close
 * component:  General => Taxonomy


Old description:

> 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.

New description:

 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.

--

Comment:

 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:
 [source:tags/3.8.1/src/wp-includes/category-template.php#L694]

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


More information about the wp-trac mailing list