Changeset 48840
- Timestamp:
- 08/21/2020 10:30:06 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/class-wp-terms-list-table.php
r48586 r48840 130 130 $this->set_pagination_args( 131 131 array( 132 'total_items' => wp_count_terms( $this->screen->taxonomy, compact( 'search' ) ), 132 'total_items' => wp_count_terms( 133 array( 134 'taxonomy' => $this->screen->taxonomy, 135 'search' => $search, 136 ) 137 ), 133 138 'per_page' => $tags_per_page, 134 139 ) -
trunk/src/wp-admin/includes/nav-menu.php
r48586 r48840 726 726 $num_pages = ceil( 727 727 wp_count_terms( 728 $taxonomy_name,729 728 array_merge( 730 729 $args, -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php
r48782 r48840 264 264 unset( $count_args['number'], $count_args['offset'] ); 265 265 266 $total_terms = wp_count_terms( $ this->taxonomy, $count_args );266 $total_terms = wp_count_terms( $count_args ); 267 267 268 268 // wp_count_terms() can return a falsey value when the term has no children. -
trunk/src/wp-includes/sitemaps/providers/class-wp-sitemaps-taxonomies.php
r48782 r48840 151 151 } 152 152 153 $term_count = wp_count_terms( $t axonomy, $this->get_taxonomies_query_args( $taxonomy ) );153 $term_count = wp_count_terms( $this->get_taxonomies_query_args( $taxonomy ) ); 154 154 155 155 return (int) ceil( $term_count / wp_sitemaps_get_max_urls( $this->object_type ) ); -
trunk/src/wp-includes/taxonomy.php
r48782 r48840 1731 1731 * 1732 1732 * @since 2.3.0 1733 * 1734 * @param string $taxonomy Taxonomy name. 1735 * @param array|string $args Optional. Array of arguments that get passed to get_terms(). 1736 * Default empty array. 1733 * @since 5.6.0 Changed the function signature so that the `$args` array can be provided as the first parameter. 1734 * 1735 * @param array|string $args Optional. Array of arguments that get passed to get_terms(). 1736 * Default empty array. 1737 * @param array|string $deprecated Taxonomy name. 1737 1738 * @return array|int|WP_Error Number of terms in that taxonomy or WP_Error if the taxonomy does not exist. 1738 1739 */ 1739 function wp_count_terms( $taxonomy, $args = array() ) { 1740 $defaults = array( 1741 'taxonomy' => $taxonomy, 1742 'hide_empty' => false, 1743 ); 1744 $args = wp_parse_args( $args, $defaults ); 1740 function wp_count_terms( $args = array(), $deprecated = array() ) { 1741 // Check whether function is used with legacy signature `$taxonomy` and `$args`. 1742 $use_legacy_args = $args && ( is_string( $args ) && taxonomy_exists( $args ) || is_array( $args ) && wp_is_numeric_array( $args ) ); 1743 1744 $defaults = array( 'hide_empty' => false ); 1745 if ( $use_legacy_args ) { 1746 $defaults['taxonomy'] = $args; 1747 $args = $deprecated; 1748 } 1749 1750 $args = wp_parse_args( $args, $defaults ); 1745 1751 1746 1752 // Backward compatibility. -
trunk/tests/phpunit/tests/import/import.php
r47526 r48840 66 66 67 67 // Check that terms were imported correctly. 68 $this->assertEquals( 30, wp_count_terms( 'category') );69 $this->assertEquals( 3, wp_count_terms( 'post_tag') );68 $this->assertEquals( 30, wp_count_terms( array( 'taxonomy' => 'category' ) ) ); 69 $this->assertEquals( 3, wp_count_terms( array( 'taxonomy' => 'post_tag' ) ) ); 70 70 $foo = get_term_by( 'slug', 'foo', 'category' ); 71 71 $this->assertEquals( 0, $foo->parent ); … … 231 231 $this->assertEquals( 'author@example.org', $author->user_email ); 232 232 233 $this->assertEquals( 30, wp_count_terms( 'category') );234 $this->assertEquals( 3, wp_count_terms( 'post_tag') );233 $this->assertEquals( 30, wp_count_terms( array( 'taxonomy' => 'category' ) ) ); 234 $this->assertEquals( 3, wp_count_terms( array( 'taxonomy' => 'post_tag' ) ) ); 235 235 $foo = get_term_by( 'slug', 'foo', 'category' ); 236 236 $this->assertEquals( 0, $foo->parent ); -
trunk/tests/phpunit/tests/term.php
r48043 r48840 66 66 */ 67 67 function test_wp_count_terms() { 68 $count = wp_count_terms( 'category', array( 'hide_empty' => true ) ); 68 $count = wp_count_terms( 69 array( 70 'hide_empty' => true, 71 'taxonomy' => 'category', 72 ) 73 ); 69 74 // There are 5 posts, all Uncategorized. 70 75 $this->assertEquals( 1, $count ); 76 } 77 78 /** 79 * @ticket 36399 80 */ 81 function test_wp_count_terms_legacy_interoperability() { 82 self::factory()->tag->create_many( 5 ); 83 84 // Counts all terms (1 default category, 5 tags). 85 $count = wp_count_terms(); 86 $this->assertEquals( 6, $count ); 87 88 // Counts only tags (5), with both current and legacy signature. 89 // Legacy usage should not trigger deprecated notice. 90 $count = wp_count_terms( array( 'taxonomy' => 'post_tag' ) ); 91 $legacy_count = wp_count_terms( 'post_tag' ); 92 $this->assertEquals( 5, $count ); 93 $this->assertEquals( $count, $legacy_count ); 71 94 } 72 95 … … 128 151 $this->assertNull( category_exists( $term ) ); 129 152 130 $initial_count = wp_count_terms( 'category');153 $initial_count = wp_count_terms( array( 'taxonomy' => 'category' ) ); 131 154 132 155 $t = wp_insert_category( array( 'cat_name' => $term ) ); … … 134 157 $this->assertNotWPError( $t ); 135 158 $this->assertTrue( $t > 0 ); 136 $this->assertEquals( $initial_count + 1, wp_count_terms( 'category') );159 $this->assertEquals( $initial_count + 1, wp_count_terms( array( 'taxonomy' => 'category' ) ) ); 137 160 138 161 // Make sure the term exists. … … 144 167 $this->assertNull( term_exists( $term ) ); 145 168 $this->assertNull( term_exists( $t ) ); 146 $this->assertEquals( $initial_count, wp_count_terms( 'category') );169 $this->assertEquals( $initial_count, wp_count_terms( array( 'taxonomy' => 'category' ) ) ); 147 170 } 148 171 -
trunk/tests/phpunit/tests/term/wpInsertTerm.php
r47122 r48840 25 25 $this->assertNull( term_exists( $term ) ); 26 26 27 $initial_count = wp_count_terms( $taxonomy);27 $initial_count = wp_count_terms( array( 'taxonomy' => $taxonomy ) ); 28 28 29 29 $t = wp_insert_term( $term, $taxonomy ); … … 32 32 $this->assertTrue( $t['term_id'] > 0 ); 33 33 $this->assertTrue( $t['term_taxonomy_id'] > 0 ); 34 $this->assertEquals( $initial_count + 1, wp_count_terms( $taxonomy) );34 $this->assertEquals( $initial_count + 1, wp_count_terms( array( 'taxonomy' => $taxonomy ) ) ); 35 35 36 36 // Make sure the term exists. … … 44 44 $this->assertNull( term_exists( $term ) ); 45 45 $this->assertNull( term_exists( $t['term_id'] ) ); 46 $this->assertEquals( $initial_count, wp_count_terms( $taxonomy) );46 $this->assertEquals( $initial_count, wp_count_terms( array( 'taxonomy' => $taxonomy ) ) ); 47 47 } 48 48
Note: See TracChangeset
for help on using the changeset viewer.