Make WordPress Core

Ticket #48772: 48772.3.diff

File 48772.3.diff, 3.2 KB (added by donmhico, 5 years ago)
  • src/wp-includes/comment-template.php

    diff --git src/wp-includes/comment-template.php src/wp-includes/comment-template.php
    index 42f3ef2023..7add13ff40 100644
    function get_comments_number( $post_id = 0 ) { 
    869869 * Display the language string for the number of comments the current post has.
    870870 *
    871871 * @since 0.71
     872 * @since 5.4 Added `$post_id` as the fifth parameter.
    872873 *
    873  * @param string $zero       Optional. Text for no comments. Default false.
    874  * @param string $one        Optional. Text for one comment. Default false.
    875  * @param string $more       Optional. Text for more than one comment. Default false.
    876  * @param string $deprecated Not used.
     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 * @param int|WP_Post $post_id    Optional. Post ID or WP_Post object. Default is the global `$post`.
    877879 */
    878 function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) {
     880function comments_number( $zero = false, $one = false, $more = false, $deprecated = '', $post_id = 0 ) {
    879881        if ( ! empty( $deprecated ) ) {
    880882                _deprecated_argument( __FUNCTION__, '1.3.0' );
    881883        }
    882         echo get_comments_number_text( $zero, $one, $more );
     884        echo get_comments_number_text( $zero, $one, $more, $post_id );
    883885}
    884886
    885887/**
    886888 * Display the language string for the number of comments the current post has.
    887889 *
    888890 * @since 4.0.0
     891 * @since 5.4 Added `$post_id` as the fourth parameter to allow the usage of the function outside the loop.
    889892 *
    890893 * @param string $zero Optional. Text for no comments. Default false.
    891894 * @param string $one  Optional. Text for one comment. Default false.
    892895 * @param string $more Optional. Text for more than one comment. Default false.
     896 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is the global `$post`.
     897 * @return string Language string for the number of comments a post has.
    893898 */
    894 function get_comments_number_text( $zero = false, $one = false, $more = false ) {
    895         $number = get_comments_number();
     899function get_comments_number_text( $zero = false, $one = false, $more = false, $post_id = 0 ) {
     900        $number = get_comments_number( $post_id );
    896901
    897902        if ( $number > 1 ) {
    898903                if ( false === $more ) {
  • tests/phpunit/tests/comment/template.php

    diff --git tests/phpunit/tests/comment/template.php tests/phpunit/tests/comment/template.php
    index cabfb36da0..73f6493bda 100644
    class Tests_Comment_Template extends WP_UnitTestCase { 
    5252
    5353        }
    5454
     55        /**
     56         * @ticket 48772
     57         */
     58        function test_get_comments_number_text_outside_loop() {
     59                $post_id = $this->factory->post->create();
     60                $this->factory->comment->create_post_comments( $post_id, 6 );
     61
     62                $comments_number_text = get_comments_number_text( false, false, false, $post_id );
     63
     64                $this->assertEquals( sprintf( _n( '%s Comment', '%s Comments', 6 ), '6' ), $comments_number_text );
     65        }
     66
    5567        /**
    5668         * @ticket 13651
    5769         * @dataProvider data_get_comments_number_text_declension