Make WordPress Core

Ticket #48772: 48772.5.diff

File 48772.5.diff, 3.4 KB (added by garrett-eclipse, 5 years ago)

Oops minor copy-paste issue in my .4 patch fixed here

  • src/wp-includes/comment-template.php

     
    870870 * Displays the language string for the number of comments the current post has.
    871871 *
    872872 * @since 0.71
     873 * @since 5.4.0 Added `$post_id` as the fifth parameter.
    873874 *
    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.
     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`.
    878880 */
    879 function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) {
     881function comments_number( $zero = false, $one = false, $more = false, $deprecated = '', $post_id = 0 ) {
    880882        if ( ! empty( $deprecated ) ) {
    881883                _deprecated_argument( __FUNCTION__, '1.3.0' );
    882884        }
    883         echo get_comments_number_text( $zero, $one, $more );
     885        echo get_comments_number_text( $zero, $one, $more, $post_id );
    884886}
    885887
    886888/**
     
    887889 * Displays the language string for the number of comments the current post has.
    888890 *
    889891 * @since 4.0.0
     892 * @since 5.4.0 Added `$post_id` as the fourth parameter to allow the usage of the function outside of the loop.
    890893 *
    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 * @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.
    894899 */
    895 function get_comments_number_text( $zero = false, $one = false, $more = false ) {
    896         $number = get_comments_number();
     900function get_comments_number_text( $zero = false, $one = false, $more = false, $post_id = 0 ) {
     901        $number = get_comments_number( $post_id );
    897902
    898903        if ( $number > 1 ) {
    899904                if ( false === $more ) {
  • tests/phpunit/tests/comment/template.php

     
    5353        }
    5454
    5555        /**
     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
     67        /**
    5668         * @ticket 13651
    5769         * @dataProvider data_get_comments_number_text_declension
    5870         */