Skip to content

Pingbacks: add option to auto-approve self-pingbacks#1

Draft
arcangelini wants to merge 3 commits into
trunkfrom
add/pingback-auto-accept-self
Draft

Pingbacks: add option to auto-approve self-pingbacks#1
arcangelini wants to merge 3 commits into
trunkfrom
add/pingback-auto-accept-self

Conversation

@arcangelini

Copy link
Copy Markdown
Owner

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

  • A new pre_comment_approved filter, wp_auto_approve_self_pingback(), runs only on pending pingbacks. It leaves approved, spam, trash, and WP_Error verdicts untouched.
  • A pingback is treated as a self-pingback when its comment_author_url (the source URL core has already fetched and verified links to the target post) resolves to a local post via url_to_postid(). url_to_postid() enforces same-host matching, so external URLs never qualify.
  • Trackbacks are intentionally excluded — only XML-RPC pingbacks have a verified source link; trackbacks are forgeable.

Changes

  • comment.php — new wp_auto_approve_self_pingback() callback.
  • default-filters.php — hook it to pre_comment_approved (priority 10).
  • option.php — register the auto_approve_self_pingbacks setting (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.php covering: 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 real pre_comment_approved chain.

@arcangelini arcangelini self-assigned this Jun 23, 2026
@arcangelini arcangelini changed the title Comments: Add option to auto-approve self-pingbacks Pingbacks: add option to auto-approve self-pingbacks Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant