Make WordPress Core


Ignore:
Timestamp:
08/06/2026 09:30:58 AM (2 months ago)
Author:
youknowriad
Message:

Pings/Trackbacks: Auto-approve pingbacks and trackbacks from the same site.

Pings carry no email address, so they never satisfy the
comment_previously_approved option, which is enabled by default. Every ping
is held for moderation indefinitely as a result, including the ones a site
sends to itself when a new post links to an older one.

Approve a ping whose source URL resolves to a published post on this site.
Existing moderation checks still take precedence, and the new
auto_approve_ping filter controls the decision.

Props annezazu, avcascade, chriscct7, desrosj, dshanske, eurello, matt,
mohkatz, SergeyBiryukov, stevegrunwell.
Fixes #65016.

File:
1 edited

Legend:

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

    r53863 r63036  
    7272                $result = wp_allow_comment( $comment_data );
    7373        }
     74
     75        /**
     76         * @ticket 65016
     77         *
     78         * @dataProvider data_should_approve_a_pingback_only_when_it_comes_from_this_site
     79         *
     80         * @param bool $is_self_ping Whether the pingback should come from this site.
     81         * @param int  $expected     The expected approval status.
     82         */
     83        public function test_should_approve_a_pingback_only_when_it_comes_from_this_site( $is_self_ping, $expected ) {
     84                update_option( 'comment_previously_approved', '1' );
     85
     86                $source_url = $is_self_ping
     87                        ? get_permalink( self::factory()->post->create() )
     88                        : 'http://example.com/their-post/';
     89
     90                $comment_data = array(
     91                        'comment_post_ID'      => self::$post_id,
     92                        'comment_author'       => 'The Linking Post',
     93                        'comment_author_email' => '',
     94                        'comment_author_url'   => $source_url,
     95                        'comment_content'      => '[…] an earlier post of mine […]',
     96                        'comment_author_IP'    => '192.168.0.1',
     97                        'comment_parent'       => 0,
     98                        'comment_date_gmt'     => gmdate( 'Y-m-d H:i:s' ),
     99                        'comment_agent'        => 'WordPress/6.8',
     100                        'comment_type'         => 'pingback',
     101                );
     102
     103                $this->assertSame( $expected, wp_allow_comment( $comment_data ) );
     104        }
     105
     106        /**
     107         * Data provider.
     108         *
     109         * @return array[]
     110         */
     111        public function data_should_approve_a_pingback_only_when_it_comes_from_this_site() {
     112                return array(
     113                        'a pingback from this site'    => array( true, 1 ),
     114                        'a pingback from another site' => array( false, 0 ),
     115                );
     116        }
    74117}
Note: See TracChangeset for help on using the changeset viewer.