Changeset 47276
- Timestamp:
- 02/11/2020 08:39:12 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/comment-template.php
r47219 r47276 871 871 * 872 872 * @since 0.71 873 * 874 * @param string $zero Optional. Text for no comments. Default false. 875 * @param string $one Optional. Text for one comment. Default false. 876 * @param string $more Optional. Text for more than one comment. Default false. 877 * @param string $deprecated Not used. 878 */ 879 function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) { 873 * @since 5.4.0 Added the `$post_id` parameter. 874 * 875 * @param string $zero Optional. Text for no comments. Default false. 876 * @param string $one Optional. Text for one comment. Default false. 877 * @param string $more Optional. Text for more than one comment. Default false. 878 * @param string $deprecated Not used. 879 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is the global `$post`. 880 */ 881 function comments_number( $zero = false, $one = false, $more = false, $deprecated = '', $post_id = 0 ) { 880 882 if ( ! empty( $deprecated ) ) { 881 883 _deprecated_argument( __FUNCTION__, '1.3.0' ); 882 884 } 883 echo get_comments_number_text( $zero, $one, $more );885 echo get_comments_number_text( $zero, $one, $more, $post_id ); 884 886 } 885 887 … … 888 890 * 889 891 * @since 4.0.0 890 * 891 * @param string $zero Optional. Text for no comments. Default false. 892 * @param string $one Optional. Text for one comment. Default false. 893 * @param string $more Optional. Text for more than one comment. Default false. 894 */ 895 function get_comments_number_text( $zero = false, $one = false, $more = false ) { 896 $number = get_comments_number(); 892 * @since 5.4.0 Added the `$post_id` parameter to allow using the function outside of the loop. 893 * 894 * @param string $zero Optional. Text for no comments. Default false. 895 * @param string $one Optional. Text for one comment. Default false. 896 * @param string $more Optional. Text for more than one comment. Default false. 897 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is the global `$post`. 898 * @return string Language string for the number of comments a post has. 899 */ 900 function get_comments_number_text( $zero = false, $one = false, $more = false, $post_id = 0 ) { 901 $number = get_comments_number( $post_id ); 897 902 898 903 if ( $number > 1 ) { -
trunk/tests/phpunit/tests/comment/template.php
r47122 r47276 29 29 30 30 $this->assertEquals( 12, get_comments_number() ); 31 } 32 33 /** 34 * @ticket 48772 35 */ 36 function test_get_comments_number_text_with_post_id() { 37 $post_id = $this->factory->post->create(); 38 $this->factory->comment->create_post_comments( $post_id, 6 ); 39 40 $comments_number_text = get_comments_number_text( false, false, false, $post_id ); 41 42 $this->assertEquals( sprintf( _n( '%s Comment', '%s Comments', 6 ), '6' ), $comments_number_text ); 31 43 } 32 44
Note: See TracChangeset
for help on using the changeset viewer.