Make WordPress Core

Changeset 58335


Ignore:
Timestamp:
06/04/2024 03:27:57 PM (2 years ago)
Author:
SergeyBiryukov
Message:

Comments: Ensure the correct comment ID type is passed to get_comment_author.

The $comment_id parameter of the get_comment_author filter is documented as a numeric string, however in case a non-existing comment ID is passed to the get_comment_author() function, it could be an integer instead.

This commit resolves the issue and adds a PHPUnit test demonstrating the behavior.

Includes updating get_comment_author_url() unit tests for consistency.

Follow-up to [41127], [52818].

Props david.binda.
Fixes #60475.

Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/comment-template.php

    r57685 r58335  
    2525        $comment = get_comment( $comment_id );
    2626
    27         $comment_id = ! empty( $comment->comment_ID ) ? $comment->comment_ID : $comment_id;
     27        $comment_id = ! empty( $comment->comment_ID ) ? $comment->comment_ID : (string) $comment_id;
    2828
    2929        if ( empty( $comment->comment_author ) ) {
  • trunk/tests/phpunit/tests/comment/getCommentAuthorEmailLink.php

    r53863 r58335  
    66 */
    77class Tests_Comment_GetCommentAuthorEmailLink extends WP_UnitTestCase {
     8
    89        public static $comment;
    910
  • trunk/tests/phpunit/tests/comment/getCommentAuthorUrl.php

    r54704 r58335  
    77 */
    88class Tests_Comment_GetCommentAuthorUrl extends WP_UnitTestCase {
    9         public function get_comment_author_url_filter( $url, $id, $comment ) {
    10                 $this->assertSame( $id, $comment->comment_ID );
    119
    12                 return $url;
     10        private static $comment;
     11
     12        public static function set_up_before_class() {
     13                parent::set_up_before_class();
     14
     15                self::$comment = self::factory()->comment->create_and_get(
     16                        array(
     17                                'comment_post_ID' => 0,
     18                        )
     19                );
     20        }
     21
     22        public function get_comment_author_url_filter( $comment_author_url, $comment_id, $comment ) {
     23                $this->assertSame( $comment_id, $comment->comment_ID );
     24
     25                return $comment_author_url;
    1326        }
    1427
     
    1730         */
    1831        public function test_comment_author_url_passes_correct_comment_id() {
    19                 $comment = self::factory()->comment->create_and_get(
    20                         array(
    21                                 'comment_post_ID' => 0,
    22                         )
    23                 );
    24 
    2532                add_filter( 'get_comment_author_url', array( $this, 'get_comment_author_url_filter' ), 99, 3 );
    2633
    27                 get_comment_author_url( $comment );
    28 
    29                 remove_filter( 'get_comment_author_url', array( $this, 'get_comment_author_url_filter' ), 99 );
     34                get_comment_author_url( self::$comment );
    3035        }
    3136}
  • trunk/tests/phpunit/tests/comment/getCommentAuthorUrlLink.php

    r55661 r58335  
    77 */
    88class Tests_Comment_GetCommentAuthorUrlLink extends WP_UnitTestCase {
     9
    910        protected static $comments = array();
    1011
Note: See TracChangeset for help on using the changeset viewer.