Skip to content

Abilities: Only register the plugin's copies of core abilities when WordPress core does not provide them - #1251

Merged
dkotter merged 9 commits into
WordPress:developfrom
the-hercules:fix/1240-defer-to-core-abilities
Nov 5, 2026
Merged

dkotter merged 9 commits into
WordPress:developfrom
the-hercules:fix/1240-defer-to-core-abilities

Conversation

@the-hercules

@the-hercules the-hercules commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

What?

Closes #1240. Follow up to #1206, #1207 and #1208.

The plugin's copies of core/settings-get, core/users-query and core/content-query now stand down when the ability is already registered, instead of unregistering the core ability and replacing it.

Why?

WordPress 7.2 registers these three abilities natively. Until now, each plugin class unregistered the core copy and registered its own on wp_abilities_api_init priority 11, regardless of the WordPress version. On 7.2+ that means:

  • A core security release that patches one of these abilities is silently overridden on every site running the plugin, until the plugin ships its own release. The abilities are reachable by any authenticated user over REST and, with the MCP Adapter active, by AI agents.
  • On later WordPress versions, a plugin that has not been updated keeps replacing the newer core ability with an older input and output shape.

This was raised in the security audit of the three PRs and confirmed in #1208 (comment).

How?

  • Settings.php, Users.php, Content.php: when wp_has_ability() reports the ability is registered, register() returns instead of calling wp_unregister_ability(). In Settings::register() the check moves to the top, so the plugin does not repeat the initial settings registration that core already did.
  • The class docblocks state the core revision each class was last synced from: Content r64907, Users r65002, Settings r64346. Settings does not port r64500 because required_capabilities is not supported before WordPress 7.2; a // Plugin: comment marks this.
  • Tests:
    • test_override_replaces_existing_core_* are renamed to test_keeps_existing_core_* and assert that the core-provided ability is kept.
    • New test_registers_plugin_copy_when_core_has_none tests cover the path for WordPress before 7.2.
    • SettingsTest, Content_RestTest and Users_RestTest remove any core-provided copy in setUp(), so on WordPress trunk they keep testing the plugin's copy rather than core's.

On the points left open in the issue:

  • The decision keys on wp_has_ability() alone. It is the simplest option, needs no version table, and also stands down for a third-party polyfill.
  • No wpai_override_core_abilities filter is added. Unit tests remove the core copy directly, and manual testing of the plugin's copy works on WordPress below 7.2. A filter is public API that is easy to add later but hard to remove, so it can be a follow-up if it turns out to be needed.

Note: on WordPress trunk, UsersTest::test_string_input_from_direct_calls_is_normalized fails with input[where][ids] has duplicate items. That test removes the core copy itself and runs the same code as develop, so the failure is not caused by this change. It comes from stricter input validation in trunk.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Implementing the change and tests, looking up the core sync revisions, and running the checks on WordPress 7.1 and trunk; final implementation and tests were reviewed by me.

Screenshots or screencast

Not applicable: no UI changes.

Before After
N/A N/A

Changelog Entry

Changed - The plugin's copies of the core/settings-get, core/users-query and core/content-query abilities are only registered when WordPress does not provide them. On WordPress 7.2 and later, the core abilities, including their security fixes, are the ones in effect.

Open WordPress Playground Preview

@the-hercules
the-hercules requested a review from a team October 30, 2026 11:58
@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: the-hercules <thehercules@git.wordpress.org>
Co-authored-by: dkotter <dkotter@git.wordpress.org>
Co-authored-by: saarnilauri <laurisaarni@git.wordpress.org>
Co-authored-by: gziolo <gziolo@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@codecov

codecov Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.14%. Comparing base (f8d6436) to head (4787c1c).

Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #1251   +/-   ##
==========================================
  Coverage      85.14%   85.14%           
  Complexity      4825     4825           
==========================================
  Files            189      189           
  Lines          17910    17910           
==========================================
  Hits           15249    15249           
  Misses          2661     2661           
Flag Coverage Δ
unit 85.14% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread CHANGELOG.md Resolved

@saarnilauri saarnilauri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this.

First a small change:

  1. Content.php is missing the "last synced" docblock line

The PR description says "The class docblocks state the core revision each class was last synced from: Content r64907, Users r65002, Settings r64346." The diff only adds that line to Settings.php and Users.php:

Please, add it to the Content class docblock.

Second item is more complex.

  1. The plugin's Content copy is behind core r65045, which is security-relevant (follow-up, or fix here)

Core r65045 (2026-10-30, "Restrict content-query author visibility to viewable post types") changed get_visible_author() to count only publicly viewable post types:

// core trunk
$post_types = array_values( array_filter( get_post_types( array( 'show_in_abilities' => true ), 'names' ), 'is_post_type_viewable' ) );

The plugin still has the old line (includes/Abilities/Content/Content.php:1448):

$post_types = get_post_types( array( 'show_in_abilities' => true ), 'names' );

Without the filter, a published post in a show_in_abilities but non-viewable post type makes that author's slug visible to any logged-in user, which is an author-enumeration side channel. After this PR, 7.2+ sites get core's fixed version. Sites on 7.0/7.1 keep the plugin copy, so the gap stays there.

This is exactly the kind of drift #1240 is about, so I'd either:

  • port r65045 in this PR (one line plus the docblock wording, with core's test_author_slug_is_not_exposed_by_posts_in_a_non_viewable_post_type test), and record the sync as r65045; or
  • open a follow-up issue and link it here, keeping the docblock at r64907 so the gap is visible.

@gziolo @dkotter What do you think? Should this PR complete the sync or add a followup for it?

Comment thread includes/Abilities/Users/Users.php Resolved
Comment thread includes/Abilities/Content/Content.php Resolved
@dkotter

dkotter commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

@gziolo @dkotter What do you think? Should this PR complete the sync or add a followup for it?

I typically like to keep PRs focused on a single thing but seems easy/small enough to pull those changes in here so feels like we might as well do that

@dkotter dkotter added this to the 1.6.0 milestone Nov 5, 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.

Only register the plugin's copies of core/settings-get, core/users-query and core/content-query when WordPress core does not provide them

4 participants