diff -r c7c34916027a -r 177826044cd9 wp/wp-includes/category-template.php --- a/wp/wp-includes/category-template.php Mon Oct 14 18:06:33 2019 +0200 +++ b/wp/wp-includes/category-template.php Mon Oct 14 18:28:13 2019 +0200 @@ -17,13 +17,15 @@ * @return string Link on success, empty string if category does not exist. */ function get_category_link( $category ) { - if ( ! is_object( $category ) ) + if ( ! is_object( $category ) ) { $category = (int) $category; + } $category = get_term_link( $category ); - if ( is_wp_error( $category ) ) + if ( is_wp_error( $category ) ) { return ''; + } return $category; } @@ -69,17 +71,18 @@ * @since 0.71 * * @param int $id Optional, default to current post ID. The post ID. - * @return array Array of WP_Term objects, one for each category assigned to the post. + * @return WP_Term[] Array of WP_Term objects, one for each category assigned to the post. */ function get_the_category( $id = false ) { $categories = get_the_terms( $id, 'category' ); - if ( ! $categories || is_wp_error( $categories ) ) + if ( ! $categories || is_wp_error( $categories ) ) { $categories = array(); + } $categories = array_values( $categories ); foreach ( array_keys( $categories ) as $key ) { - _make_cat_compat( $categories[$key] ); + _make_cat_compat( $categories[ $key ] ); } /** @@ -88,8 +91,8 @@ * @since 3.1.0 * @since 4.4.0 Added `$id` parameter. * - * @param array $categories An array of categories to return for the post. - * @param int $id ID of the post. + * @param WP_Term[] $categories An array of categories to return for the post. + * @param int|false $id ID of the post. */ return apply_filters( 'get_the_categories', $categories, $id ); } @@ -103,11 +106,12 @@ * @return string|WP_Error Category name on success, WP_Error on failure. */ function get_the_category_by_ID( $cat_ID ) { - $cat_ID = (int) $cat_ID; + $cat_ID = (int) $cat_ID; $category = get_term( $cat_ID ); - if ( is_wp_error( $category ) ) + if ( is_wp_error( $category ) ) { return $category; + } return ( $category ) ? $category->name : ''; } @@ -137,9 +141,9 @@ * * @since 4.4.0 * - * @param array $categories An array of the post's categories. - * @param int|bool $post_id ID of the post we're retrieving categories for. When `false`, we assume the - * current post in the loop. + * @param WP_Term[] $categories An array of the post's categories. + * @param int|bool $post_id ID of the post we're retrieving categories for. When `false`, we assume the + * current post in the loop. */ $categories = apply_filters( 'the_category_list', get_the_category( $post_id ), $post_id ); @@ -157,42 +161,47 @@ $thelist .= "\n\t
type => link
',
'taxonomy => link_category
'
)
@@ -348,7 +365,7 @@
$args['taxonomy'] = 'link_category';
}
- $r = wp_parse_args( $args, $defaults );
+ $r = wp_parse_args( $args, $defaults );
$option_none_value = $r['option_none_value'];
if ( ! isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) {
@@ -367,9 +384,9 @@
unset( $get_terms_args['name'] );
$categories = get_terms( $r['taxonomy'], $get_terms_args );
- $name = esc_attr( $r['name'] );
- $class = esc_attr( $r['class'] );
- $id = $r['id'] ? esc_attr( $r['id'] ) : $name;
+ $name = esc_attr( $r['name'] );
+ $class = esc_attr( $r['class'] );
+ $id = $r['id'] ? esc_attr( $r['id'] ) : $name;
$required = $r['required'] ? 'required' : '';
if ( ! $r['hide_if_empty'] || ! empty( $categories ) ) {
@@ -395,7 +412,7 @@
* @param WP_Term|null $category The category object, or null if there's no corresponding category.
*/
$show_option_none = apply_filters( 'list_cats', $r['show_option_none'], null );
- $output .= "\t\n";
+ $output .= "\t\n";
}
if ( ! empty( $categories ) ) {
@@ -404,16 +421,16 @@
/** This filter is documented in wp-includes/category-template.php */
$show_option_all = apply_filters( 'list_cats', $r['show_option_all'], null );
- $selected = ( '0' === strval($r['selected']) ) ? " selected='selected'" : '';
- $output .= "\t\n";
+ $selected = ( '0' === strval( $r['selected'] ) ) ? " selected='selected'" : '';
+ $output .= "\t\n";
}
if ( $r['show_option_none'] ) {
/** This filter is documented in wp-includes/category-template.php */
$show_option_none = apply_filters( 'list_cats', $r['show_option_none'], null );
- $selected = selected( $option_none_value, $r['selected'], false );
- $output .= "\t\n";
+ $selected = selected( $option_none_value, $r['selected'], false );
+ $output .= "\t\n";
}
if ( $r['hierarchical'] ) {
@@ -522,8 +539,9 @@
$r = wp_parse_args( $args, $defaults );
- if ( !isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] )
+ if ( ! isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) {
$r['pad_counts'] = true;
+ }
// Descendants of exclusions should be excluded too.
if ( true == $r['hierarchical'] ) {
@@ -538,17 +556,18 @@
}
$r['exclude_tree'] = $exclude_tree;
- $r['exclude'] = '';
+ $r['exclude'] = '';
}
- if ( ! isset( $r['class'] ) )
+ if ( ! isset( $r['class'] ) ) {
$r['class'] = ( 'category' == $r['taxonomy'] ) ? 'categories' : $r['taxonomy'];
+ }
if ( ! taxonomy_exists( $r['taxonomy'] ) ) {
return false;
}
- $show_option_all = $r['show_option_all'];
+ $show_option_all = $r['show_option_all'];
$show_option_none = $r['show_option_none'];
$categories = get_categories( $r );
@@ -638,64 +657,74 @@
}
/**
- * Display tag cloud.
- *
- * The text size is set by the 'smallest' and 'largest' arguments, which will
- * use the 'unit' argument value for the CSS text size unit. The 'format'
- * argument can be 'flat' (default), 'list', or 'array'. The flat value for the
- * 'format' argument will separate tags with spaces. The list value for the
- * 'format' argument will format the tags in a UL HTML list. The array value for
- * the 'format' argument will return in PHP array type format.
- *
- * The 'orderby' argument will accept 'name' or 'count' and defaults to 'name'.
- * The 'order' is the direction to sort, defaults to 'ASC' and can be 'DESC'.
- *
- * 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' argument is a nooped plural from _n_noop() to generate the
- * text for the tag link count.
- *
- * The 'topic_count_text_callback' argument is a function, which given the count
- * of the posts with that tag returns a text for the tag link count.
- *
- * The 'post_type' argument is used only when 'link' is set to 'edit'. It determines the post_type
- * passed to edit.php for the popular tags edit links.
- *
- * The 'exclude' and 'include' arguments are used for the get_tags() function. Only one
- * should be used, because only one will be used and the other ignored, if they are both set.
+ * Displays a tag cloud.
*
* @since 2.3.0
* @since 4.8.0 Added the `show_count` argument.
*
- * @param array|string|null $args Optional. Override default arguments.
+ * @param array|string $args {
+ * Optional. Array or string of arguments for displaying a tag cloud. See wp_generate_tag_cloud()
+ * and get_terms() for the full lists of arguments that can be passed in `$args`.
+ *
+ * @type int $number The number of tags to display. Accepts any positive integer
+ * or zero to return all. Default 0 (all tags).
+ * @type string $link Whether to display term editing links or term permalinks.
+ * Accepts 'edit' and 'view'. Default 'view'.
+ * @type string $post_type The post type. Used to highlight the proper post type menu
+ * on the linked edit page. Defaults to the first post type
+ * associated with the taxonomy.
+ * @type bool $echo Whether or not to echo the return value. Default true.
+ * }
* @return void|array Generated tag cloud, only if no failures and 'array' is set for the 'format' argument.
* Otherwise, this function outputs the tag cloud.
*/
function wp_tag_cloud( $args = '' ) {
$defaults = array(
- 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,
- 'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC',
- 'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'post_tag', 'post_type' => '', 'echo' => true,
+ 'smallest' => 8,
+ 'largest' => 22,
+ 'unit' => 'pt',
+ 'number' => 45,
+ 'format' => 'flat',
+ 'separator' => "\n",
+ 'orderby' => 'name',
+ 'order' => 'ASC',
+ 'exclude' => '',
+ 'include' => '',
+ 'link' => 'view',
+ 'taxonomy' => 'post_tag',
+ 'post_type' => '',
+ 'echo' => true,
'show_count' => 0,
);
- $args = wp_parse_args( $args, $defaults );
+ $args = wp_parse_args( $args, $defaults );
- $tags = get_terms( $args['taxonomy'], array_merge( $args, array( 'orderby' => 'count', 'order' => 'DESC' ) ) ); // Always query top tags
+ $tags = get_terms(
+ $args['taxonomy'],
+ array_merge(
+ $args,
+ array(
+ 'orderby' => 'count',
+ 'order' => 'DESC',
+ )
+ )
+ ); // Always query top tags
- if ( empty( $tags ) || is_wp_error( $tags ) )
+ if ( empty( $tags ) || is_wp_error( $tags ) ) {
return;
+ }
foreach ( $tags as $key => $tag ) {
- if ( 'edit' == $args['link'] )
+ if ( 'edit' == $args['link'] ) {
$link = get_edit_term_link( $tag->term_id, $tag->taxonomy, $args['post_type'] );
- else
- $link = get_term_link( intval($tag->term_id), $tag->taxonomy );
- if ( is_wp_error( $link ) )
+ } else {
+ $link = get_term_link( intval( $tag->term_id ), $tag->taxonomy );
+ }
+ if ( is_wp_error( $link ) ) {
return;
+ }
$tags[ $key ]->link = $link;
- $tags[ $key ]->id = $tag->term_id;
+ $tags[ $key ]->id = $tag->term_id;
}
$return = wp_generate_tag_cloud( $tags, $args ); // Here's where those top tags get sorted according to $args
@@ -710,8 +739,9 @@
*/
$return = apply_filters( 'wp_tag_cloud', $return, $args );
- if ( 'array' == $args['format'] || empty($args['echo']) )
+ if ( 'array' == $args['format'] || empty( $args['echo'] ) ) {
return $return;
+ }
echo $return;
}
@@ -725,7 +755,7 @@
* @return int Scaled count.
*/
function default_topic_count_scale( $count ) {
- return round(log10($count + 1) * 100);
+ return round( log10( $count + 1 ) * 100 );
}
/**
@@ -735,9 +765,9 @@
* @since 2.3.0
* @since 4.8.0 Added the `show_count` argument.
*
- * @param array $tags List of tags.
+ * @param WP_Term[] $tags Array of WP_Term objects to generate the tag cloud for.
* @param string|array $args {
- * Optional. Array of string of arguments for generating a tag cloud.
+ * Optional. Array or string of arguments for generating a tag cloud.
*
* @type int $smallest Smallest font size used to display tags. Paired
* with the value of `$unit`, to determine CSS text
@@ -776,11 +806,19 @@
*/
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' => null, 'topic_count_text_callback' => null,
- 'topic_count_scale_callback' => 'default_topic_count_scale', 'filter' => 1,
- 'show_count' => 0,
+ 'smallest' => 8,
+ 'largest' => 22,
+ 'unit' => 'pt',
+ 'number' => 0,
+ 'format' => 'flat',
+ 'separator' => "\n",
+ 'orderby' => 'name',
+ 'order' => 'ASC',
+ 'topic_count_text' => null,
+ 'topic_count_text_callback' => null,
+ 'topic_count_scale_callback' => 'default_topic_count_scale',
+ 'filter' => 1,
+ 'show_count' => 0,
);
$args = wp_parse_args( $args, $defaults );
@@ -804,6 +842,7 @@
}
} elseif ( isset( $args['single_text'] ) && isset( $args['multiple_text'] ) ) {
// If no callback exists, look for the old-style single_text and multiple_text arguments.
+ // phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralSingle,WordPress.WP.I18n.NonSingularStringLiteralPlural
$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.
@@ -815,8 +854,8 @@
*
* @since 2.8.0
*
- * @param array $tags Ordered array of terms.
- * @param array $args An array of tag cloud arguments.
+ * @param WP_Term[] $tags Ordered array of terms.
+ * @param array $args An array of tag cloud arguments.
*/
$tags_sorted = apply_filters( 'tag_cloud_sort', $tags, $args );
if ( empty( $tags_sorted ) ) {
@@ -843,23 +882,26 @@
}
}
- if ( $args['number'] > 0 )
+ if ( $args['number'] > 0 ) {
$tags = array_slice( $tags, 0, $args['number'] );
+ }
- $counts = array();
+ $counts = array();
$real_counts = array(); // For the alt tag
foreach ( (array) $tags as $key => $tag ) {
$real_counts[ $key ] = $tag->count;
- $counts[ $key ] = call_user_func( $args['topic_count_scale_callback'], $tag->count );
+ $counts[ $key ] = call_user_func( $args['topic_count_scale_callback'], $tag->count );
}
$min_count = min( $counts );
- $spread = max( $counts ) - $min_count;
- if ( $spread <= 0 )
+ $spread = max( $counts ) - $min_count;
+ if ( $spread <= 0 ) {
$spread = 1;
+ }
$font_spread = $args['largest'] - $args['smallest'];
- if ( $font_spread < 0 )
+ if ( $font_spread < 0 ) {
$font_spread = 1;
+ }
$font_step = $font_spread / $spread;
$aria_label = false;
@@ -883,7 +925,7 @@
foreach ( $tags as $key => $tag ) {
$tag_id = isset( $tag->id ) ? $tag->id : $key;
- $count = $counts[ $key ];
+ $count = $counts[ $key ];
$real_count = $real_counts[ $key ];
if ( $translate_nooped_plural ) {
@@ -921,7 +963,7 @@
// Generate the output links array.
foreach ( $tags_data as $key => $tag_data ) {
$class = $tag_data['class'] . ' tag-link-position-' . ( $key + 1 );
- $a[] = sprintf(
+ $a[] = sprintf(
'%6$s%7$s',
esc_url( $tag_data['url'] ),
$tag_data['role'],
@@ -934,20 +976,20 @@
}
switch ( $args['format'] ) {
- case 'array' :
+ case 'array':
$return =& $a;
break;
- case 'list' :
+ case 'list':
/*
* Force role="list", as some browsers (sic: Safari 10) don't expose to assistive
* technologies the default role when the list is styled with `list-style: none`.
* Note: this is redundant but doesn't harm.
*/
- $return = "