Make WordPress Core


Ignore:
Timestamp:
09/11/2024 03:38:20 PM (2 years ago)
Author:
flixos90
Message:

Comments: Ensure $comment_id parameter on get_edit_comment_link filter is always a comment ID.

Follow up to [58875].

Props david.binda, peterwilsoncc, mukesh27, davidbaumwald.
Fixes #61727.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/link/getEditCommentLink.php

    r58875 r59012  
    128128                $this->assertSame( $expected_url, $actual_url );
    129129        }
     130
     131        /**
     132         * Tests that the 'get_edit_comment_link' filter receives the comment ID, even when a comment object is passed.
     133         *
     134         * @ticket 61727
     135         */
     136        public function test_get_edit_comment_link_filter_uses_id() {
     137                // Add a filter just to catch the $comment_id filter parameter value.
     138                $comment_id_filter_param = null;
     139                add_filter(
     140                        'get_edit_comment_link',
     141                        function ( $location, $comment_id ) use ( &$comment_id_filter_param ) {
     142                                $comment_id_filter_param = $comment_id;
     143                                return $location;
     144                        },
     145                        10,
     146                        2
     147                );
     148
     149                // Pass a comment object to get_edit_comment_link().
     150                get_edit_comment_link( get_comment( self::$comment_id ) );
     151
     152                // The filter should still always receive the comment ID, not the object.
     153                $this->assertSame( self::$comment_id, $comment_id_filter_param );
     154        }
    130155}
Note: See TracChangeset for help on using the changeset viewer.