From a6b80a326a24016e369dd092192fe6f1799cade2 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 25 Feb 2020 17:32:34 +0000 Subject: [PATCH] Comments: Restore the fourth parameter of `comments_number()` as `$post_id`, for consistency with `get_comments_number_text()`. The parameter was previously used as the number of comments, marked as deprecated in [5101]. Given that it's been deprecated for the last 13 years, it should be safe to undeprecate and repurpose it for a cleaner function signature, instead of adding a fifth parameter. Follow-up to [47276]. Fixes #48772. git-svn-id: https://develop.svn.wordpress.org/trunk@47366 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/comment-template.php | 8 ++------ tests/phpunit/tests/comment/template.php | 7 +++++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/comment-template.php b/src/wp-includes/comment-template.php index ad61a63e11..9d20c6bbd2 100644 --- a/src/wp-includes/comment-template.php +++ b/src/wp-includes/comment-template.php @@ -870,18 +870,14 @@ function get_comments_number( $post_id = 0 ) { * Displays the language string for the number of comments the current post has. * * @since 0.71 - * @since 5.4.0 Added the `$post_id` parameter. + * @since 5.4.0 The `$deprecated` parameter was changed to `$post_id`. * * @param string $zero Optional. Text for no comments. Default false. * @param string $one Optional. Text for one comment. Default false. * @param string $more Optional. Text for more than one comment. Default false. - * @param string $deprecated Not used. * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is the global `$post`. */ -function comments_number( $zero = false, $one = false, $more = false, $deprecated = '', $post_id = 0 ) { - if ( ! empty( $deprecated ) ) { - _deprecated_argument( __FUNCTION__, '1.3.0' ); - } +function comments_number( $zero = false, $one = false, $more = false, $post_id = 0 ) { echo get_comments_number_text( $zero, $one, $more, $post_id ); } diff --git a/tests/phpunit/tests/comment/template.php b/tests/phpunit/tests/comment/template.php index 186829093a..b5c52bd5df 100644 --- a/tests/phpunit/tests/comment/template.php +++ b/tests/phpunit/tests/comment/template.php @@ -40,6 +40,13 @@ class Tests_Comment_Template extends WP_UnitTestCase { $comments_number_text = get_comments_number_text( false, false, false, $post_id ); $this->assertEquals( sprintf( _n( '%s Comment', '%s Comments', 6 ), '6' ), $comments_number_text ); + + ob_start(); + comments_number( false, false, false, $post_id ); + $comments_number_text = ob_get_clean(); + + $this->assertEquals( sprintf( _n( '%s Comment', '%s Comments', 6 ), '6' ), $comments_number_text ); + } /**