Pingbacks: add option to auto-approve self-pingbacks#1
Draft
arcangelini wants to merge 3 commits into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an opt-in Discussion setting, "Automatically approve pingbacks from this site", that auto-approves self-pingbacks — the pingbacks WordPress generates when one post on a site links to another post on the same site. When enabled, these are approved instead of being held for moderation.
The feature is off by default, so there is no behavior change for existing sites unless an admin explicitly enables it.
How it works
pre_comment_approvedfilter,wp_auto_approve_self_pingback(), runs only on pending pingbacks. It leaves approved, spam, trash, andWP_Errorverdicts untouched.comment_author_url(the source URL core has already fetched and verified links to the target post) resolves to a local post viaurl_to_postid().url_to_postid()enforces same-host matching, so external URLs never qualify.Changes
comment.php— newwp_auto_approve_self_pingback()callback.default-filters.php— hook it topre_comment_approved(priority 10).option.php— register theauto_approve_self_pingbackssetting (REST-exposed, boolean).options-discussion.php— add the checkbox to the Discussion settings screen.options.php— allow-list the option for saving.schema.php— seed the option default (0) on install.Testing
Adds
tests/phpunit/tests/comment/autoApproveSelfPingback.phpcovering: approval when enabled, no-op when disabled, non-pingback types ignored, external URLs rejected, non-pending statuses (spam/trash/approved/WP_Error) never overridden, and the filter wiring through the realpre_comment_approvedchain.