Make WordPress Core


Ignore:
Timestamp:
02/11/2020 08:39:12 PM (5 years ago)
Author:
SergeyBiryukov
Message:

Comments: Add a $post_id parameter to get_comments_number_text() and comments_number().

This allow for using these functions outside of the loop.

Props donmhico, garrett-eclipse, Hinjiriyo, imath.
Fixes #48772.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/comment/template.php

    r47122 r47276  
    2929
    3030        $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 );
    3143    }
    3244
Note: See TracChangeset for help on using the changeset viewer.