[wp-trac] [WordPress Trac] #24656: Tag Cloud generation return object for manipulation

WordPress Trac noreply at wordpress.org
Fri May 15 20:00:58 UTC 2015


#24656: Tag Cloud generation return object for manipulation
-------------------------------------------------+-------------------------
 Reporter:  ysalame                              |       Owner:
     Type:  enhancement                          |      Status:  new
 Priority:  normal                               |   Milestone:  Future
Component:  Taxonomy                             |  Release
 Severity:  normal                               |     Version:  3.5
 Keywords:  needs-patch needs-unit-tests good-   |  Resolution:
  first-bug                                      |     Focuses:
-------------------------------------------------+-------------------------
Changes (by boonebgorges):

 * keywords:  needs-refresh => needs-patch needs-unit-tests good-first-bug
 * milestone:  Awaiting Review => Future Release


Comment:

 ysalame - Thanks for the patch, and sorry for the lack of feedback. Having
 better control over the customizability of tag cloud markup is a good
 idea.

 If we're going to pass structured data around, let's do it in arrays
 rather than objects. This is more in keeping with practice throughout WP.

 I'm not sure I see the value in *returning* structured data from the
 function. The purpose of the function is to generate markup; changing it
 to return structured data in an arbitrary format suggests the need for
 another function. That being said, I don't think another function is
 really necessary. How about this: Break the `foreach ( $tags as $key =>
 $tag )` loop into two loops. The first one would assemble an array of
 structured data:

 {{{
 $tag_data = array();
 foreach ( $tags as $key => $tag ) {
     $tag_data[] = array(
         'count' => $counts[ $key ],
         'real_count' => $real_counts[ $key ],
         // etc
     );
 }
 }}}

 Then pass it through a filter before creating the anchor tags:

 {{{
 $tag_data = apply_filters( 'wp_generate_tag_cloud_data', $tag_data );

 $a = array();
 foreach ( $tag_data as $tag_d ) {
     $a[] = "<a href='" // ...
 }
 }}}

 This way, we don't have to maintain a new function return value, but you
 get full customizability.

 I'd like basic test coverage for `wp_generate_tag_cloud()` before making
 these changes.

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


More information about the wp-trac mailing list