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/src/wp-includes/comment.php

    r63012 r63036  
    2121 * approved.
    2222 *
     23 * Pingbacks originating from this site are automatically approved, as the link
     24 * they report was created by someone who can already publish here.
     25 *
    2326 * If all checks pass, the function will return true.
    2427 *
    2528 * @since 1.2.0
     29 * @since 7.2.0 Pingbacks from this site are no longer held for moderation.
    2630 *
    2731 * @global wpdb $wpdb WordPress database abstraction object.
    … …  
    162166                                return false;
    163167                        }
     168                } elseif ( 'pingback' === $comment_type ) {
     169                        /*
     170                         * Only pingbacks are considered. A pingback is verified before it reaches
     171                         * this point: the source page is fetched, it must link to the target, and
     172                         * the comment is built from that fetched page. A trackback carries no such
     173                         * proof. Its source URL, title, and excerpt are unverified request data, so
     174                         * a forged trackback naming a local post as its source would be approved.
     175                         */
     176
     177                        // url_to_postid() compares hostnames, so it returns 0 for any URL that only appears to be local.
     178                        $source_id = url_to_postid( wp_unslash( $url ) );
     179
     180                        // Approve pingbacks reporting a link that someone who can already publish here created.
     181                        $approve_pingback = $source_id > 0 && 'publish' === get_post_status( $source_id );
     182
     183                        /**
     184                         * Filters whether a pingback is approved without being held for moderation.
     185                         *
     186                         * Defaults to true for pingbacks originating from a published post on this
     187                         * site, and false for every other pingback. Trackbacks are never considered,
     188                         * as they cannot be verified.
     189                         *
     190                         * @since 7.2.0
     191                         *
     192                         * @param bool   $approve_pingback Whether to approve the pingback.
     193                         * @param int    $source_id        ID of the post on this site the pingback
     194                         *                                 originated from, or 0 if it came from elsewhere.
     195                         * @param string $url              The URL the pingback was sent from.
     196                         */
     197                        return (bool) apply_filters( 'auto_approve_pingback', $approve_pingback, $source_id, $url );
    164198                } else {
    165199                        return false;
Note: See TracChangeset for help on using the changeset viewer.