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. Built from https://develop.svn.wordpress.org/trunk@27376 git-svn-id: http://core.svn.wordpress.org/trunk@27225 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
849ce35cb9
commit
cfc20a5f64
|
@ -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[] = "<a href='$tag_link' class='tag-link-$tag_id' title='" . esc_attr( call_user_func( $topic_count_text_callback, $real_count, $tag, $args ) ) . "' style='font-size: " .
|
||||
|
||||
if ( $translate_nooped_plural ) {
|
||||
$title_attribute = sprintf( translate_nooped_plural( $translate_nooped_plural, $real_count ), number_format_i18n( $real_count ) );
|
||||
} else {
|
||||
$title_attribute = call_user_func( $topic_count_text_callback, $real_count, $tag, $args );
|
||||
}
|
||||
|
||||
$a[] = "<a href='$tag_link' class='tag-link-$tag_id' title='" . esc_attr( $title_attribute ) . "' style='font-size: " .
|
||||
str_replace( ',', '.', ( $smallest + ( ( $count - $min_count ) * $font_step ) ) )
|
||||
. "$unit;'>$tag_name</a>";
|
||||
}
|
||||
|
@ -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
|
||||
//
|
||||
|
|
|
@ -3418,3 +3418,15 @@ function rich_edit_exists() {
|
|||
* @deprecated 3.9.0
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue