From 8b532c17d2aa7e565f5bc89411f9cca761170b86 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Mon, 3 Mar 2014 17:28:07 +0000 Subject: [PATCH] Accept nooped plurals in wp_generate_tag_cloud() / wp_tag_cloud(). Renders topic_count_text_callback more or less obsolete. It can still be used, but passing a plural is easier. fixes #27262. see #7989, #14424. git-svn-id: https://develop.svn.wordpress.org/trunk@27376 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/category-template.php | 73 ++++++++++++++------------- src/wp-includes/deprecated.php | 14 ++++- 2 files changed, 51 insertions(+), 36 deletions(-) diff --git a/src/wp-includes/category-template.php b/src/wp-includes/category-template.php index 3ed78380a6..fa991bba41 100644 --- a/src/wp-includes/category-template.php +++ b/src/wp-includes/category-template.php @@ -515,8 +515,11 @@ function wp_list_categories( $args = '' ) { * The 'number' argument is how many tags to return. By default, the limit will * be to return the top 45 tags in the tag cloud list. * - * The 'topic_count_text_callback' argument is a function, which, given the count - * of the posts with that tag, returns a text for the tooltip of the tag link. + * The 'topic_count_text' argument is a nooped plural from _n_noop() to generate the + * text for the tooltip of the tag link. + * + * The 'topic_count_text_callback' argument is a function, which given the count + * of the posts with that tag returns a text for the tooltip of the tag link. * * The 'exclude' and 'include' arguments are used for the {@link get_tags()} * function. Only one should be used, because only one will be used and the @@ -562,16 +565,6 @@ function wp_tag_cloud( $args = '' ) { echo $return; } -/** - * Default text for tooltip for tag links - * - * @param integer $count number of posts with that tag - * @return string text for the tooltip of a tag link. - */ -function default_topic_count_text( $count ) { - return sprintf( _n('%s topic', '%s topics', $count), number_format_i18n( $count ) ); -} - /** * Default topic count scaling for tag links * @@ -603,8 +596,11 @@ function default_topic_count_scale( $count ) { * The 'number' argument is how many tags to return. By default, the limit will * be to return the entire tag cloud list. * + * The 'topic_count_text' argument is a nooped plural from _n_noop() to generate the + * text for the tooltip of the tag link. + * * The 'topic_count_text_callback' argument is a function, which given the count - * of the posts with that tag returns a text for the tooltip of the tag link. + * of the posts with that tag returns a text for the tooltip of the tag link. * * @todo Complete functionality. * @since 2.3.0 @@ -617,20 +613,35 @@ function wp_generate_tag_cloud( $tags, $args = '' ) { $defaults = array( 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 0, 'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC', - 'topic_count_text_callback' => 'default_topic_count_text', + 'topic_count_text' => null, 'topic_count_text_callback' => null, 'topic_count_scale_callback' => 'default_topic_count_scale', 'filter' => 1, ); - if ( !isset( $args['topic_count_text_callback'] ) && isset( $args['single_text'] ) && isset( $args['multiple_text'] ) ) { - $args['topic_count_text_callback'] = '_plugin_topic_count'; - } - $args = wp_parse_args( $args, $defaults ); - extract( $args ); + extract( $args, EXTR_SKIP ); if ( empty( $tags ) ) return; + // Juggle topic count tooltips: + if ( isset( $args['topic_count_text'] ) ) { + // First look for nooped plural support via topic_count_text. + $translate_nooped_plural = $args['topic_count_text']; + } elseif ( ! empty( $args['topic_count_text_callback'] ) ) { + // Look for the alternative callback style. Ignore the previous default. + if ( $args['topic_count_text_callback'] === 'default_topic_count_text' ) { + $translate_nooped_plural = _n_noop( '%s topic', '%s topics' ); + } else { + $translate_nooped_plural = false; + } + } elseif ( isset( $args['single_text'] ) && isset( $args['multiple_text'] ) ) { + // If no callback exists, look for the old-style single_text and multiple_text arguments. + $translate_nooped_plural = _n_noop( $args['single_text'], $args['multiple_text'] ); + } else { + // This is the default for when no callback, plural, or argument is passed in. + $translate_nooped_plural = _n_noop( '%s topic', '%s topics' ); + } + $tags_sorted = apply_filters( 'tag_cloud_sort', $tags, $args ); if ( $tags_sorted != $tags ) { // the tags have been sorted by a plugin $tags = $tags_sorted; @@ -677,7 +688,14 @@ function wp_generate_tag_cloud( $tags, $args = '' ) { $tag_link = '#' != $tag->link ? esc_url( $tag->link ) : '#'; $tag_id = isset($tags[ $key ]->id) ? $tags[ $key ]->id : $key; $tag_name = $tags[ $key ]->name; - $a[] = "$tag_name"; } @@ -722,21 +740,6 @@ function _wp_object_count_sort_cb( $a, $b ) { return ( $a->count > $b->count ); } -/** - * Default text for tooltip for tag links - * - * @since 3.9.0 - * @access private - * - * @param integer $count Number of posts with that tag. - * @param object $tag Tag object. - * @param array $args Arguments for the tag cloud. - * @return string Text for the tooltip of a tag link. - */ -function _plugin_topic_count( $count, $tag, $args ) { - return sprintf( 1 == $count? $args['single_text'] : $args['multiple_text'], number_format_i18n( $count ) ); -} - // // Helper functions // diff --git a/src/wp-includes/deprecated.php b/src/wp-includes/deprecated.php index b2dea9a8c3..5823ee8296 100644 --- a/src/wp-includes/deprecated.php +++ b/src/wp-includes/deprecated.php @@ -3417,4 +3417,16 @@ function rich_edit_exists() { * @since 2.6.0 * @deprecated 3.9.0 */ -function wp_style_loader_src() {} \ No newline at end of file +function wp_style_loader_src() {} + + +/** + * Old callback for tag link tooltips. + * + * @since 2.7.0 + * @deprecated 3.9.0 + * @access private + */ +function default_topic_count_text( $count ) { + return $count; +}