Abilities: Add support for ability deprecation - #10507
Conversation
|
Hi @JasonTheAdams! 👋 Thank you for your contribution to WordPress! 💖 It looks like this is your first pull request to No one monitors this repository for new pull requests. Pull requests must be attached to a Trac ticket to be considered for inclusion in WordPress Core. To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description. Pull requests are never merged on GitHub. The WordPress codebase continues to be managed through the SVN repository that this GitHub repository mirrors. Please feel free to open pull requests to work on any contribution you are making. More information about how GitHub pull requests can be used to contribute to WordPress can be found in the Core Handbook. Please include automated tests. Including tests in your pull request is one way to help your patch be considered faster. To learn about WordPress' test suites, visit the Automated Testing page in the handbook. If you have not had a chance, please review the Contribute with Code page in the WordPress Core Handbook. The Developer Hub also documents the various coding standards that are followed:
Thank you, |
|
Some topics to discuss:
|
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
VersionWhen looking over If it is useful, then we'd need a way for an Ability to note the version, since this function is called automatically within meta.deprecated = false;
meta.deprecated = true;
meta.deprecated = array(
'version' => '1.2.3',
'replacement' => 'foo/v2/my-ability'
); // implied true with further informationI'm kind of partial to the array structure as it only adds a single property to ReplacementThis does feel more valuable, as it would be nice for someone using an Ability to know which Ability is intended to be its successor, if there is one available. As above, we could have a Filtering in
|
|
Hey @JasonTheAdams I touched a bit on your more general comments over on https://core.trac.wordpress.org/ticket/64209#comment:13, but tl;dr I agree with your comparison to ability filtering, and think any deprecation pattern should also be done as a holistic enhancement once the needs are more clearly defined. Which yeah will prob only come after/alongside a basic mechanism for filtering (but IMO no need to tunnel vision that in the rush to ship this) (Syndication is one directional to Trac, replying here to signpost future visitors.) PS: congrats on your "first contribution to WordPress" 🎉🙃🎉 |
bbda8b6 to
e21c3ee
Compare
|
The branch has been updated and rebased onto the latest
The structured metadata follows the general pattern used by Tests cover validation, defaults, execution notices, exact-name execution, discovery filtering, and REST API behavior. The new and changed API documentation uses A fresh CI run was triggered by the updated branch. Feedback welcome@justlevine and @JasonTheAdams, could you please review this revised version when you have time? I would especially value your feedback on the |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.
Suppressed comments (2)
src/wp-includes/abilities-api/class-wp-ability.php:399
replacementis documented and exposed as a namespaced ability name, but this validation accepts any non-empty string (for example,not an ability). That leaves consumers and deprecation notices with an unusable migration target. Validate this field with the same ability-name rule used byWP_Abilities_Registry::register(); existence need not be required because registration order can vary.
if ( ! is_string( $args['meta']['deprecated'][ $key ] ) || '' === $args['meta']['deprecated'][ $key ] ) {
throw new InvalidArgumentException(
sprintf(
/* translators: %s: Deprecation metadata key. */
__( 'The ability deprecation `%s` value should be a non-empty string.' ),
$key
)
);
src/wp-includes/rest-api/endpoints/class-wp-rest-abilities-v1-list-controller.php:410
- The schema accepts
trueas a deprecation-status filter, but registered abilities can only storefalseor an array.get_items()forwards the resulting boolean to_wp_get_abilities_match_meta(), whose strict comparison meansmeta[deprecated]=truecan never match a deprecated ability. Normalizetrueto the existingarray()sentinel before callingwp_get_abilities()(and cover that REST query), or constrain this schema and provide another REST-representable way to request only deprecated abilities.
'deprecated' => array(
'description' => __( 'Limit results by deprecation status or details.' ),
'type' => array( 'boolean', 'object' ),
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
This PR adds a standard way to deprecate an ability without removing it.
Proposed changes
meta.deprecatedproperty. Its default value isfalse.since,replacement, andmessage._deprecated_ability()and show a deprecation notice when the ability runs.wp_get_abilities()or REST API filters.Why use structured metadata?
falseclearly means that an ability is active. An array keeps all migration details together and makes them available to PHP, REST API clients, and other tools without parsing a message.This follows the general pattern used by
@wordpress/deprecated, which also stores deprecation details as structured options. The proposed ability API uses a smaller set of fields that fits server-side ability metadata.Tests
The tests cover metadata defaults and validation, execution notices, exact-name execution, discovery filtering, and REST API behavior.
Trac ticket: https://core.trac.wordpress.org/ticket/64209