Changeset 65161
- Timestamp:
- 11/01/2026 05:58:25 AM (less than one hour ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
src/wp-includes/category-template.php (modified) (2 diffs)
-
tests/phpunit/tests/term/wpGenerateTagCloud.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/category-template.php
r64234 r65161 820 820 * Optional. Array or string of arguments for generating a tag cloud. 821 821 * 822 * @type int $smallest Smallest font size used to display tags. Paired823 * with the value of `$unit`, to determine CSS text824 * size unit. Default 8 (pt).825 * @type int $largest Largest font size used to display tags. Paired826 * with the value of `$unit`, to determine CSS text827 * size unit. Default 22 (pt).828 * @type string $unit CSS text size unit to use with the `$smallest`829 * and `$largest` values. Accepts any valid CSS text830 * size unit. Default 'pt'.831 * @type int $number The number of tags to return. Accepts any832 * positive integer or zero to return all.833 * Default 0.834 * @type string $format Format to display the tag cloud in. Accepts 'flat'835 * (tags separated with spaces), 'list' (tags displayed836 * in an unordered list), or 'array' (returns an array).837 * Default 'flat'.838 * @type string $separator HTML or text to separate the tags. Default "\n" (newline).839 * @type string $orderby Value to order tags by. Accepts 'name' or 'count'.840 * Default 'name'. The {@see 'tag_cloud_sort'} filter841 * can also affect how tags are sorted.842 * @type string $order How to order the tags. Accepts 'ASC' (ascending),843 * 'DESC' (descending), or 'RAND' (random). Default 'ASC'.844 * @type int|bool $filter Whether to enable filtering of the final output845 * via {@see 'wp_generate_tag_cloud'}. Default 1.846 * @type array $topic_count_text Nooped plural text from _n_noop() to supply to847 * tag counts. Default null.848 * @type callable $topic_count_text_callback Callback used to generate nooped plural text for849 * tag counts based on the count. Default null.850 * @type callable $topic_count_scale_callback Callback used to determine the tag count scaling851 * value. Default default_topic_count_scale().852 * @type bool|int $show_count Whether to display the tag counts. Default 0. Accepts853 * 0, 1, or their bool equivalents.822 * @type int|float $smallest Smallest font size used to display tags. Paired 823 * with the value of `$unit`, to determine CSS text 824 * size unit. Default 8 (pt). 825 * @type int|float $largest Largest font size used to display tags. Paired 826 * with the value of `$unit`, to determine CSS text 827 * size unit. Default 22 (pt). 828 * @type string $unit CSS text size unit to use with the `$smallest` 829 * and `$largest` values. Accepts any valid CSS text 830 * size unit. Default 'pt'. 831 * @type int $number The number of tags to return. Accepts any 832 * positive integer or zero to return all. 833 * Default 0. 834 * @type string $format Format to display the tag cloud in. Accepts 'flat' 835 * (tags separated with spaces), 'list' (tags displayed 836 * in an unordered list), or 'array' (returns an array). 837 * Default 'flat'. 838 * @type string $separator HTML or text to separate the tags. Default "\n" (newline). 839 * @type string $orderby Value to order tags by. Accepts 'name' or 'count'. 840 * Default 'name'. The {@see 'tag_cloud_sort'} filter 841 * can also affect how tags are sorted. 842 * @type string $order How to order the tags. Accepts 'ASC' (ascending), 843 * 'DESC' (descending), or 'RAND' (random). Default 'ASC'. 844 * @type int|bool $filter Whether to enable filtering of the final output 845 * via {@see 'wp_generate_tag_cloud'}. Default 1. 846 * @type array $topic_count_text Nooped plural text from _n_noop() to supply to 847 * tag counts. Default null. 848 * @type callable $topic_count_text_callback Callback used to generate nooped plural text for 849 * tag counts based on the count. Default null. 850 * @type callable $topic_count_scale_callback Callback used to determine the tag count scaling 851 * value. Default default_topic_count_scale(). 852 * @type bool|int $show_count Whether to display the tag counts. Default 0. Accepts 853 * 0, 1, or their bool equivalents. 854 854 * } 855 855 * @return string|string[] Tag cloud as a string or an array, depending on 'format' argument. … … 971 971 * Tag Cloud widget), regardless of the tags font size 972 972 */ 973 if ( $args['show_count'] || 0 !== $font_spread) {973 if ( $args['show_count'] || $font_spread > 0 ) { 974 974 $aria_label = true; 975 975 } -
trunk/tests/phpunit/tests/term/wpGenerateTagCloud.php
r65018 r65161 304 304 305 305 /** 306 * Tests that the aria-label is only output when font sizes differ or counts are shown. 307 * 308 * @ticket 65817 309 * 310 * @covers ::wp_generate_tag_cloud 311 * 312 * @dataProvider data_aria_label_font_sizes 313 * 314 * @param int|float $smallest Smallest font size. 315 * @param int|float $largest Largest font size. 316 * @param int $show_count Whether to show tag counts. 317 * @param bool $expect_aria_label Whether an aria-label is expected. 318 */ 319 public function test_aria_label_font_sizes( $smallest, $largest, int $show_count, bool $expect_aria_label ) { 320 register_taxonomy( 'wptests_tax', 'post' ); 321 $term_ids = self::factory()->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) ); 322 $posts = self::factory()->post->create_many( 2 ); 323 324 wp_set_post_terms( $posts[0], $term_ids, 'wptests_tax' ); 325 wp_set_post_terms( $posts[1], array( $term_ids[1] ), 'wptests_tax' ); 326 327 $term_objects = $this->retrieve_terms( 328 array( 329 'include' => $term_ids, 330 ), 331 'wptests_tax' 332 ); 333 334 $actual = wp_generate_tag_cloud( 335 $term_objects, 336 array( 337 'format' => 'array', 338 'smallest' => $smallest, 339 'largest' => $largest, 340 'show_count' => $show_count, 341 ) 342 ); 343 344 $this->assertCount( 2, $actual ); 345 346 $expected_aria_labels = array( 347 $term_objects[0]->name . ' (1 item)', 348 $term_objects[1]->name . ' (2 items)', 349 ); 350 foreach ( $actual as $i => $link ) { 351 $processor = new WP_HTML_Tag_Processor( $link ); 352 $this->assertTrue( $processor->next_tag( 'A' ), 'Expected the tag cloud item to be a link.' ); 353 $this->assertSame( 354 $expect_aria_label ? $expected_aria_labels[ $i ] : null, 355 $processor->get_attribute( 'aria-label' ), 356 'Expected the aria-label attribute to be ' . ( $expect_aria_label ? 'present' : 'absent' ) . '.' 357 ); 358 } 359 } 360 361 /** 362 * Data provider for {@see self::test_aria_label_font_sizes()}. 363 * 364 * @return array<non-falsy-string, array{ 0: int|float, 1: int|float, 2: int, 3: bool }> 365 */ 366 public static function data_aria_label_font_sizes(): array { 367 return array( 368 'equal int sizes' => array( 12, 12, 0, false ), 369 'equal float sizes' => array( 1.2, 1.2, 0, false ), 370 'equal integral float sizes' => array( 12.0, 12.0, 0, false ), 371 'different int sizes' => array( 8, 22, 0, true ), 372 'different float sizes' => array( 0.8, 1.5, 0, true ), 373 'equal float sizes with count' => array( 1.2, 1.2, 1, true ), 374 'smallest larger than largest' => array( 22.5, 8.5, 0, true ), 375 ); 376 } 377 378 /** 306 379 * Helper method retrieve the created terms. 307 380 * 308 381 * @param array $get_terms_args Options passed to get_terms() 309 * @return array382 * @return WP_Term[] 310 383 */ 311 384 protected function retrieve_terms( $get_terms_args, $taxonomy = 'post_tag' ) {
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)