Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,25 @@ The entries below describe the current prototype state._
error can name the refused field, and the delete capability is re-checked
right before removal. Ships with the package-authored `media` ability
category (core trunk has no media category to copy).
- `wp/terms-query` — tier `experimental` (incubating under the `wp/` prefix,
no name or schema promises until it files a core proposal): faithful port
of the read-only terms query ability from
[WordPress/ai PR #1099](https://github.com/WordPress/ai/pull/1099) by
@jorgefilipecosta. Reads the terms of taxonomies exposed to abilities — a
single term by ID (optionally guarded by `taxonomy`) or by `taxonomy` +
`slug`, or a paginated collection (`terms`/`total`/`total_pages`) filtered
by search, include, exclude, hierarchical parent, post, and emptiness;
`fields` selects the returned subset (always with the ID) with a lean
default set that omits the description and link, and `parent` only for
hierarchical taxonomies. Keeps the PR's documented term-endpoint quirks: a
missing, hidden, or taxonomy-mismatched term is denied like an unreadable
one (so terms cannot be probed), and the `post` filter's specific errors
come from the execute callback while the permission callback stays generic.
The taxonomies are exposed through the `show_in_abilities` opt-in — the
new `taxonomy_show_in_abilities` support feature (native detection, with a
polyfill marking the built-in `category` and `post_tag` on the cores that
lack the flag — verified: all currently supported ones, 7.1 stable and
7.2-beta3 included), served through the content category.
### Removed

- `wp/post-create` — the self-authored experimental write-ability prototype
Expand Down
25 changes: 25 additions & 0 deletions KNOWN-ISSUES.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,31 @@ until core decides otherwise:
settings endpoint skips the setting without an error.
- `settings-update` is not registered when every exposed setting is
read-only (multisite), where the endpoint always exists.
- `wp/terms-query` (WordPress/ai PR #1099):
- A missing, hidden, or taxonomy-mismatched term is denied like an unreadable
one — a generic permission denial (no 404 vs 403 distinction), so terms
cannot be probed through the ability. A direct (unvalidated) call reports
it as `terms_term_invalid` instead.
- The `post` filter's failures are specific only through the execute
callback (`terms_post_invalid_id` 400 / `terms_forbidden_context` 403);
the permission callback stays generic and lets them through for a
logged-in user whose taxonomy access passed, as the PR documents (the
Abilities API replaces permission errors with a generic one).
- The REST term search covers names and slugs, not descriptions; the
`description` field is the stored HTML, and `link` is the term archive
permalink — taken from `get_term_link()`, whose possible WP_Error is
assigned unchecked (as in the source PR), so a broken site link filter
would surface it in the `link` field.
- With `hide_empty`, empty parents of non-empty children appear in `terms`
but not in `total` (the term query's count leaves them out), as the PR's
output schema documents.
- The taxonomy `show_in_abilities` flag is absent from every currently
supported core (verified on 7.2-beta3 and 7.1: `WP_Taxonomy` does not
declare it, and core does not flag `category`/`post_tag`), so the
`taxonomy_show_in_abilities` polyfill marks them on both environment
branches of the matrix; a custom taxonomy's non-bool opt-in value (e.g.
`'yes'`) is not normalized to a bool, which the loose object-list match
and the ability's truthiness check read exactly like 7.2's bool cast.
- `wp/media-upload` / `wp/media-update` / `wp/media-delete` (WordPress/ai PR #1104):
- Trashing an attachment requires the site to enable the media trash
(`MEDIA_TRASH`): without it, a non-forced delete answers
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ Full rules, the promotion path, and the rename protocol are in
| `wp/media-update` | experimental | media | Port of the media update ability from [WordPress/ai PR #1104](https://github.com/WordPress/ai/pull/1104) (`core_since: null` — flips to tier `core` when it lands in WordPress core). Updates a media item by ID with the same attachment fields (the status is validated against the attachment, so `inherit` can be kept); fields left out keep their values. Returns the updated item in the edit context. Requires edit access to the item (`edit_post` for attachments, via the same projection `wp/media-query` reads with). |
| `wp/media-delete` | experimental | media | Port of the media delete ability from [WordPress/ai PR #1104](https://github.com/WordPress/ai/pull/1104) (`core_since: null` — flips to tier `core` when it lands in WordPress core). Trashes a media item by ID (an error unless the site enables media trash), or deletes it and its files permanently with `force`, returning the item under `previous`. Requires `delete_post` for attachments; the capability is re-checked just before removal. |
| `wp/settings-update` | experimental | site | Port of the settings update ability from [WordPress/ai PR #764](https://github.com/WordPress/ai/pull/764) (`core_since: null` — flips to tier `core` when it lands in WordPress core). Updates only the settings `core/settings-get` reads — every setting except `url` and `email` (read-only, and unregistered by the ability when all of them are read-only) — via a map of setting name to new value; `null` resets a setting with a registered default to it (a setting without one refuses `null`); every check (sanitize, privacy policy, stored value) runs before any write, so an error leaves every setting unchanged; the answer holds only the updated settings. Requires `manage_options`; the privacy policy page additionally requires `manage_privacy_options`. |
| `wp/terms-query` | experimental | content | Port of the read-only terms query ability from [WordPress/ai PR #1099](https://github.com/WordPress/ai/pull/1099) (`core_since: null` — flips to tier `core` when it lands in WordPress core). Reads terms of the taxonomies exposed to abilities via `show_in_abilities` (polyfilled: no currently supported core declares the taxonomy flag yet) — a single term by ID (optionally guarded by `taxonomy`) or by `taxonomy` + `slug`, or a paginated filtered collection (`terms`/`total`/`total_pages`) covering search, include, exclude, hierarchical `parent`, `post`, and `hide_empty`; `fields` picks a subset (the ID always included, `parent` for hierarchical taxonomies only). Requires an authenticated user; a missing or hidden term is denied like an unreadable one. Served through the GET run route, like the other read abilities. |

## Roadmap (not yet)

Expand All @@ -107,9 +108,11 @@ Settings writes are no longer roadmanted either: `wp/settings-update` ships
snapshot). Media read is no longer roadmanted — `wp/media-query` ships in this
package (the first experimental-tier `wp/` ability). Media writes are no longer
roadmanted either: `wp/media-upload`, `wp/media-update`, and `wp/media-delete`
ship on top of the same `media` category and field projection. Further media
or write abilities incubate under `wp/` the same way before ever carrying a
`core/` proposal.
ship on top of the same `media` category and field projection. Terms read is no
longer roadmanted either: `wp/terms-query` ships (the taxonomy opt-in flag is
the `taxonomy_show_in_abilities` support feature, polyfilled). Further media,
terms, or write abilities incubate under `wp/` the same way before ever
carrying a `core/` proposal.

## Development

Expand Down
23 changes: 23 additions & 0 deletions src/Manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,29 @@ public static function all(): array {
'renamed_from' => null,
'proposal' => 'https://github.com/WordPress/ai/pull/1105',
),
/*
* The terms query below is a faithful port of WordPress/ai PR #1099
* (author @jorgefilipecosta).
*
* Tier: experimental, incubating under the `wp/` prefix — the proposal
* below is the PR's paper trail, but the ability has NOT landed in
* core (`core_since` stays null and flips when core lands it), so its
* name and schema carry no promises yet (NAME-LIFECYCLE.md). Its
* `content` category is core-registered (the package declares it on
* pre-7.2 hosts), and the taxonomy opt-in `show_in_abilities` is
* native on 7.2+ and polyfilled on 6.9-7.1.
*/
'wp/terms-query' => array(
'name' => 'wp/terms-query',
'class' => Terms\Terms_Query::class,
'category' => 'content',
'tier' => self::TIER_EXPERIMENTAL,
'min_wp_version' => '6.9',
'core_since' => null,
'requires' => array( 'taxonomy_show_in_abilities' ),
'renamed_from' => null,
'proposal' => 'https://github.com/WordPress/ai/pull/1099',
),
);
}

Expand Down
27 changes: 24 additions & 3 deletions src/Support/Features.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

namespace WordPress\Abilities\Support;


/**
* Detection map for core support-surface features that abilities may require.
*
Expand All @@ -26,8 +25,9 @@ final class Features {
* @var array<string, string>
*/
private static $polyfills = array(
'show_in_abilities' => 'polyfills/show-in-abilities.php',
'setting_show_in_abilities' => 'polyfills/setting-show-in-abilities.php',
'show_in_abilities' => 'polyfills/show-in-abilities.php',
'setting_show_in_abilities' => 'polyfills/setting-show-in-abilities.php',
'taxonomy_show_in_abilities' => 'polyfills/taxonomy-show-in-abilities.php',
);

/**
Expand Down Expand Up @@ -57,6 +57,10 @@ public static function is_available( string $feature ): bool {
return self::is_setting_show_in_abilities_available();
}

if ( 'taxonomy_show_in_abilities' === $feature ) {
return self::is_taxonomy_show_in_abilities_available();
}

return false;
}

Expand Down Expand Up @@ -116,4 +120,21 @@ private static function is_setting_show_in_abilities_available(): bool {

return isset( self::$loaded['setting_show_in_abilities'] );
}

/**
* Detects the `show_in_abilities` taxonomy registration argument.
*
* Natively declared on WP_Taxonomy since 7.2. On 6.9-7.1 the argument
* does not exist, and it is only available once the package polyfill
* has been loaded, mirroring the polyfill-backed registration path.
*
* @return bool
*/
private static function is_taxonomy_show_in_abilities_available(): bool {
if ( class_exists( 'WP_Taxonomy', false ) && property_exists( 'WP_Taxonomy', 'show_in_abilities' ) ) {
return true;
}

return isset( self::$loaded['taxonomy_show_in_abilities'] );
}
}
81 changes: 81 additions & 0 deletions src/Support/polyfills/taxonomy-show-in-abilities.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
/**
* Polyfill for the `show_in_abilities` taxonomy registration argument.
*
* For WordPress 6.9-7.1, where the argument does not exist yet (added in 7.2,
* together with the post type argument the `show_in_abilities` polyfill
* mirrors) but abilities exposing taxonomy-gated logic, such as
* `core/terms-query`, query `get_taxonomies( array( 'show_in_abilities' => true ) )`.
*
* Semantics mirrored from core trunk, as the WordPress/ai PR #1099
* Show_In_Abilities companion marks them:
*
* - `show_in_abilities` defaults to false for every taxonomy, and only `true`
* exposes one. See WP_Taxonomy on trunk.
* - Core (trunk) opts in exactly the built-in `category` and `post_tag`
* taxonomies when registering them. This polyfill injects that same default
* through the `register_taxonomy_args` filter, mirroring
* wp-includes/taxonomy.php, and catches up the taxonomies registered before
* it loaded. The `post_format` taxonomy stays out, as on trunk: the flag's
* curations follow the taxonomies of the exposed post types, which the
* REST API serves.
* - Custom taxonomies opt in by passing the argument to register_taxonomy()
* themselves. On 6.9-7.1, register_taxonomy() assigns all registration
* arguments as object properties, so the value behaves like core's declared
* argument for both readers the ability uses: the loose object-list match of
* get_taxonomies() and the ability's own truthiness check. An explicit
* consumer value is never widened or overridden. Trunk's strict bool cast in
* WP_Taxonomy::set_props() is not mirrored for such values: every value the
* ability reads the same way on 7.2 keeps reading the same way here.
*
* Loading: through require_once, only from the Registrar (via
* Support\Features) when an ability requires the feature and core lacks it.
* Never autoloaded.
*
* Removal cue: delete this file and its Features::$polyfills map entry when
* the package's minimum supported WordPress version rises to 7.2 — every
* consuming site then has core's declared WP_Taxonomy property
* (`wp_has_abilities` hosts ≥ 7.2), the polyfill can never load again, and
* Features::is_available() reports the native property.
*
* @package WordPress\Abilities
*/

/**
* Injects the core default `show_in_abilities` values into taxonomy args.
*
* Only fills the default for the built-in taxonomies core's own registration
* exposes on trunk; any explicit value already present in the args is kept
* as-is, including an explicit `false` opt-out.
*
* @param array<mixed> $args Registration arguments for the taxonomy.
* @param string $taxonomy The taxonomy key.
* @return array<mixed> The filtered registration arguments.
*/
$wordpress_abilities_taxonomy_show_in_abilities_polyfill = static function ( $args, $taxonomy ) {
if ( ! is_array( $args ) || array_key_exists( 'show_in_abilities', $args ) ) {
return $args;
}

if ( 'category' === $taxonomy || 'post_tag' === $taxonomy ) {
$args['show_in_abilities'] = true;
}

return $args;
};

add_filter( 'register_taxonomy_args', $wordpress_abilities_taxonomy_show_in_abilities_polyfill, 10, 2 );
unset( $wordpress_abilities_taxonomy_show_in_abilities_polyfill );

/*
* Catch-up for the built-in taxonomies, which core registers during bootstrap
* and on `init` priority 0 — typically before this polyfill loads. An explicit
* consumer value on the object is never overridden.
*/
foreach ( array( 'category', 'post_tag' ) as $polyfill_taxonomy ) {
$polyfill_object = get_taxonomy( $polyfill_taxonomy );
if ( $polyfill_object instanceof WP_Taxonomy && ! property_exists( $polyfill_object, 'show_in_abilities' ) ) {
$polyfill_object->show_in_abilities = true; // @phpstan-ignore property.notFound (the property is declared on trunk hosts, mirrored here pre-7.2)
}
}
unset( $polyfill_taxonomy, $polyfill_object );
Loading
Loading