From a3d9af584c7c4765d4bd3def1bfbd26a7cf13315 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Mon, 29 Jun 2015 14:16:26 +0000 Subject: [PATCH] Introduce 'wp_generate_tag_cloud_data' filter. This filter allows developers to modify the data that is used to create tag clouds, without having to manipulate the tag cloud markup directly. As part of the refactor, this changeset also adds a few unit tests for the way `wp_generate_tag_cloud()` generates the 'title' attribute, as well as improvements to output escaping. Props flixos90, ysalame. Fixes #24656. Built from https://develop.svn.wordpress.org/trunk@32996 git-svn-id: http://core.svn.wordpress.org/trunk@32967 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/category-template.php | 42 +++++++++++++++++++++++-------- wp-includes/version.php | 2 +- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/wp-includes/category-template.php b/wp-includes/category-template.php index 459876f509..9f4e1ac74a 100644 --- a/wp-includes/category-template.php +++ b/wp-includes/category-template.php @@ -808,24 +808,46 @@ function wp_generate_tag_cloud( $tags, $args = '' ) { $font_spread = 1; $font_step = $font_spread / $spread; - $a = array(); - + // Assemble the data that will be used to generate the tag cloud markup. + $tags_data = array(); foreach ( $tags as $key => $tag ) { + $tag_id = isset( $tag->id ) ? $tag->id : $key; + $count = $counts[ $key ]; $real_count = $real_counts[ $key ]; - $tag_link = '#' != $tag->link ? esc_url( $tag->link ) : '#'; - $tag_id = isset($tags[ $key ]->id) ? $tags[ $key ]->id : $key; - $tag_name = $tags[ $key ]->name; if ( $translate_nooped_plural ) { - $title_attribute = sprintf( translate_nooped_plural( $translate_nooped_plural, $real_count ), number_format_i18n( $real_count ) ); + $title = sprintf( translate_nooped_plural( $translate_nooped_plural, $real_count ), number_format_i18n( $real_count ) ); } else { - $title_attribute = call_user_func( $args['topic_count_text_callback'], $real_count, $tag, $args ); + $title = call_user_func( $args['topic_count_text_callback'], $real_count, $tag, $args ); } - $a[] = "$tag_name"; + $tags_data[] = array( + 'id' => $tag_id, + 'url' => '#' != $tag->link ? $tag->link : '#', + 'name' => $tag->name, + 'title' => $title, + 'slug' => $tag->slug, + 'real_count' => $real_count, + 'class' => 'tag-link-' . $tag_id, + 'font_size' => $args['smallest'] + ( $count - $min_count ) * $font_step, + ); + } + + /** + * Filter the data used to generate the tag cloud. + * + * @since 4.3.0 + * + * @param array $tags_data An array of term data for term used to generate the tag cloud. + */ + $tags_data = apply_filters( 'wp_generate_tag_cloud_data', $tags_data ); + + $a = array(); + + // generate the output links array + foreach ( $tags_data as $key => $tag_data ) { + $a[] = "" . esc_html( $tag_data['name'] ) . ""; } switch ( $args['format'] ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index 8fa5aca5cd..b322944b3c 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.3-alpha-32995'; +$wp_version = '4.3-alpha-32996'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.