-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Abilities: Add support for ability deprecation #10507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from all commits
7e4028b
00629fa
e092559
7f5ff27
924d553
cc6f70c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -231,9 +231,21 @@ | |||||
| * 'show_in_rest' => false, | ||||||
| * ), | ||||||
| * | ||||||
| * Mark an ability as deprecated while keeping exact-name retrieval and execution | ||||||
| * available for backward compatibility: | ||||||
| * | ||||||
| * 'meta' => array( | ||||||
| * 'deprecated' => array( | ||||||
| * 'since' => '2.0.0', | ||||||
| * 'replacement' => 'my-plugin/new-ability', | ||||||
| * 'message' => __( 'The replacement supports the new data format.', 'my-plugin' ), | ||||||
| * ), | ||||||
| * ), | ||||||
| * | ||||||
| * @since 6.9.0 | ||||||
| * @since 7.1.0 Added the `public` meta argument. | ||||||
| * @since 7.2.0 The `category` argument is now optional and defaults to `uncategorized`. | ||||||
| * @since 7.2.0 Added the `deprecated` meta property. | ||||||
| * | ||||||
| * @see WP_Abilities_Registry::register() | ||||||
| * @see wp_register_ability_category() | ||||||
|
|
@@ -282,6 +294,15 @@ | |||||
| * clients such as the REST API, MCP, or AI agents. Seeds | ||||||
| * the default for per-channel flags like `$show_in_rest`. | ||||||
| * Defaults to false. | ||||||
| * @type false|array<string, string> $deprecated { | ||||||
| * Optional. Deprecation details. Set to an array to mark the ability as deprecated. At least one | ||||||
| * supported detail must be provided. Deprecated abilities remain available by exact name and can | ||||||
| * be explicitly included or excluded from discovery through meta filtering. Default false. | ||||||
| * | ||||||
| * @type string $since Optional. Version of the ability provider that deprecated the ability. | ||||||
| * @type string $replacement Optional. Namespaced ability to use instead. | ||||||
| * @type string $message Optional. Additional migration guidance. | ||||||
| * } | ||||||
| * @type bool $show_in_rest Optional. Whether to expose this ability in the REST API. | ||||||
| * When true, the ability can be invoked via HTTP requests. | ||||||
| * Default is the value of `$public` when set, false otherwise. | ||||||
|
|
@@ -413,6 +434,83 @@ function wp_get_ability( string $name ): ?WP_Ability { | |||||
| return $registry->get_registered( $name ); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Marks an ability as deprecated and informs when it has been used. | ||||||
| * | ||||||
| * There is a {@see 'deprecated_ability_run'} hook that will be called that can be used | ||||||
| * to get the backtrace up to what code executed the deprecated ability. | ||||||
| * | ||||||
| * The current behavior is to trigger a user error if `WP_DEBUG` is true. | ||||||
| * | ||||||
| * @since 7.2.0 | ||||||
| * | ||||||
| * @param string $ability_name The ability that was executed. | ||||||
| * @param string $version Optional. The version of the ability provider that deprecated the ability. | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we decide we do need an
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the importance of including a version here outside of consistency with other deprecation methods? Do we like that it's required there? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A version tells the end user when the behaviour they were previously relying on changed, which makes it easier for them to find out what changed (this is helpful for humans, but a requirement for AI where the training data is often outdated). Unlike a Lastly, going from non-optional arg to optional is a non-breaking change, so if in the future there's a concrete reason to knock down any Chesterton Fences that determined |
||||||
| * Default empty string. | ||||||
| * @param string $replacement Optional. The ability that should be used instead. Default empty string. | ||||||
| * @param string $message Optional. Additional migration guidance. Default empty string. | ||||||
| */ | ||||||
| function _deprecated_ability( string $ability_name, string $version = '', string $replacement = '', string $message = '' ): void { | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with the location, since they're all in the same place. I think having a distinct method makes sense as we're calling Abilities a primitive, so I think having a primitive deprecation function makes sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Can you clarify this point? The function as written and implemented is should never be called by the end user, but is only meant to be called internally by our WP_Ability class. The existence of the class (or a private method on it) doesn't make it any less of a primitive. So we if don't want anyone calling the function directly:
(Prolly also worthwhile to note that there's no |
||||||
| /** | ||||||
| * Fires when a deprecated ability is executed. | ||||||
| * | ||||||
| * @since 7.2.0 | ||||||
| * | ||||||
| * @param string $ability_name The ability that was executed. | ||||||
| * @param string $replacement The ability that should be used as a replacement. | ||||||
| * @param string $version The version of the ability provider that deprecated the ability. | ||||||
| * @param string $message Additional migration guidance. | ||||||
| */ | ||||||
| do_action( 'deprecated_ability_run', $ability_name, $replacement, $version, $message ); | ||||||
|
|
||||||
| /** | ||||||
| * Filters whether to trigger an error for deprecated abilities. | ||||||
| * | ||||||
| * @since 7.2.0 | ||||||
| * | ||||||
| * @param bool $trigger Whether to trigger the error for deprecated abilities. Default true. | ||||||
| */ | ||||||
| if ( WP_DEBUG && apply_filters( 'deprecated_ability_trigger_error', true ) ) { | ||||||
| if ( $version ) { | ||||||
| if ( $replacement ) { | ||||||
| $notice = sprintf( | ||||||
| /* translators: 1: Ability name, 2: Version number, 3: Alternative ability name. */ | ||||||
| __( 'Ability %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), | ||||||
| $ability_name, | ||||||
| $version, | ||||||
| $replacement | ||||||
| ); | ||||||
| } else { | ||||||
| $notice = sprintf( | ||||||
| /* translators: 1: Ability name, 2: Version number. */ | ||||||
| __( 'Ability %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), | ||||||
| $ability_name, | ||||||
| $version | ||||||
| ); | ||||||
| } | ||||||
| } elseif ( $replacement ) { | ||||||
| $notice = sprintf( | ||||||
| /* translators: 1: Ability name, 2: Alternative ability name. */ | ||||||
| __( 'Ability %1$s is <strong>deprecated</strong>! Use %2$s instead.' ), | ||||||
| $ability_name, | ||||||
| $replacement | ||||||
| ); | ||||||
| } else { | ||||||
| $notice = sprintf( | ||||||
| /* translators: %s: Ability name. */ | ||||||
| __( 'Ability %s is <strong>deprecated</strong> with no alternative available.' ), | ||||||
| $ability_name | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
| if ( $message ) { | ||||||
| $notice .= ' ' . $message; | ||||||
| } | ||||||
|
|
||||||
| wp_trigger_error( '', $notice, E_USER_DEPRECATED ); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Retrieves registered abilities, optionally filtered by the given arguments. | ||||||
| * | ||||||
|
|
@@ -436,6 +534,17 @@ function wp_get_ability( string $name ): ?WP_Ability { | |||||
| * // All abilities (unchanged behaviour). | ||||||
| * $abilities = wp_get_abilities(); | ||||||
| * | ||||||
| * // Exclude deprecated abilities explicitly. | ||||||
| * $abilities = wp_get_abilities( array( | ||||||
| * 'meta' => array( 'deprecated' => false ), | ||||||
| * ) ); | ||||||
| * | ||||||
| * // Return only deprecated abilities. Passing `true` matches any deprecated | ||||||
| * // ability. An array of details narrows the results further. | ||||||
| * $abilities = wp_get_abilities( array( | ||||||
| * 'meta' => array( 'deprecated' => true ), | ||||||
| * ) ); | ||||||
| * | ||||||
| * // Filter by category. | ||||||
| * $abilities = wp_get_abilities( array( 'category' => 'content' ) ); | ||||||
| * | ||||||
|
|
@@ -475,6 +584,7 @@ function wp_get_ability( string $name ): ?WP_Ability { | |||||
| * | ||||||
| * @since 6.9.0 | ||||||
| * @since 7.1.0 Added the `$args` parameter for filtering support. | ||||||
| * @since 7.2.0 Added support for filtering by the `deprecated` meta property. | ||||||
| * | ||||||
| * @see WP_Abilities_Registry::get_all_registered() | ||||||
| * | ||||||
|
|
@@ -515,6 +625,15 @@ function wp_get_abilities( array $args = array() ): array { | |||||
| $item_include_callback = isset( $args['item_include_callback'] ) && is_callable( $args['item_include_callback'] ) ? $args['item_include_callback'] : null; | ||||||
| $result_callback = isset( $args['result_callback'] ) && is_callable( $args['result_callback'] ) ? $args['result_callback'] : null; | ||||||
|
|
||||||
| /* | ||||||
| * Normalize the `deprecated` meta filter shorthand. Stored values are `false` | ||||||
| * or an array of details, so `true` becomes an empty set of conditions that | ||||||
| * matches any deprecated ability. | ||||||
| */ | ||||||
| if ( isset( $meta['deprecated'] ) && true === $meta['deprecated'] ) { | ||||||
| $meta['deprecated'] = array(); | ||||||
| } | ||||||
|
|
||||||
|
Comment on lines
627
to
+636
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noting:
If this is behaviorally intentional, I'd make it an implementation detail of function _wp_get_abilities_match_meta( array $meta, array $conditions ): bool {
foreach ( $conditions as $key => $value ) {
if ( ! array_key_exists( $key, $meta ) ) {
return false;
}
// Support `deprecated: true` as a shorthand to match all deprecated abilities.
if ( 'deprecated' === `$key` && true === $value ) {
$value = [];
}
... rest of functionHowever, since those are telltale signs of AI generated-code lacking intentionality, I'm unclear as to how much of the rest of the implementation and use of Behaviorally, I'd assume the following holistic shape when querying for abilities:
If there's human-led reasons for the current approach, I'd love to hear them and dive in to the discrepancies. If it's just "AI Slop" and lacking human intentionality, then 👆 is what I recommend we align to. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc: @gziolo (updated, hope that makes my concerns + intent clearer) |
||||||
| $matched = array(); | ||||||
|
|
||||||
| foreach ( $abilities as $name => $ability ) { | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -42,6 +42,7 @@ final class WP_Abilities_Registry { | |||||||||||||||||||||||||||||||||||||
| * @since 6.9.0 | ||||||||||||||||||||||||||||||||||||||
| * @since 7.1.0 Added the `public` meta argument. | ||||||||||||||||||||||||||||||||||||||
| * @since 7.2.0 The `category` argument is now optional and defaults to `uncategorized`. | ||||||||||||||||||||||||||||||||||||||
| * @since 7.2.0 Added the `deprecated` meta property. | ||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
| * @see wp_register_ability() | ||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -78,6 +79,15 @@ final class WP_Abilities_Registry { | |||||||||||||||||||||||||||||||||||||
| * to clients such as the REST API, MCP, or AI agents. | ||||||||||||||||||||||||||||||||||||||
| * Seeds the default for per-channel flags like | ||||||||||||||||||||||||||||||||||||||
| * `$show_in_rest`. Defaults to false. | ||||||||||||||||||||||||||||||||||||||
| * @type false|array<string, string> $deprecated { | ||||||||||||||||||||||||||||||||||||||
| * Optional. Deprecation details. Set to an array to mark the ability as deprecated. At least one | ||||||||||||||||||||||||||||||||||||||
| * supported detail must be provided. Deprecated abilities remain available by exact name and can | ||||||||||||||||||||||||||||||||||||||
| * be explicitly included or excluded from discovery through meta filtering. Default false. | ||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
| * @type string $since Optional. Version of the ability provider that deprecated the ability. | ||||||||||||||||||||||||||||||||||||||
| * @type string $replacement Optional. Namespaced ability to use instead. | ||||||||||||||||||||||||||||||||||||||
| * @type string $message Optional. Additional migration guidance. | ||||||||||||||||||||||||||||||||||||||
| * } | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+82
to
+90
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per #10507 (comment),
Suggested change
|
||||||||||||||||||||||||||||||||||||||
| * @type bool $show_in_rest Optional. Whether to expose this ability in the REST API. | ||||||||||||||||||||||||||||||||||||||
| * Default is the value of `$public` when set, false otherwise. | ||||||||||||||||||||||||||||||||||||||
| * } | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -113,6 +123,7 @@ public function register( string $name, array $args ): ?WP_Ability { | |||||||||||||||||||||||||||||||||||||
| * @since 6.9.0 | ||||||||||||||||||||||||||||||||||||||
| * @since 7.1.0 Added the `public` meta argument. | ||||||||||||||||||||||||||||||||||||||
| * @since 7.2.0 The `category` argument is now optional and defaults to `uncategorized`. | ||||||||||||||||||||||||||||||||||||||
| * @since 7.2.0 Added the `deprecated` meta property. | ||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
| * @param array<string, mixed> $args { | ||||||||||||||||||||||||||||||||||||||
| * An associative array of arguments for the ability. | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -135,6 +146,15 @@ public function register( string $name, array $args ): ?WP_Ability { | |||||||||||||||||||||||||||||||||||||
| * available to clients such as the REST API, MCP, or AI | ||||||||||||||||||||||||||||||||||||||
| * agents. Seeds the default for per-channel flags like | ||||||||||||||||||||||||||||||||||||||
| * `$show_in_rest`. Defaults to false. | ||||||||||||||||||||||||||||||||||||||
| * @type false|array<string, string> $deprecated { | ||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||||||||||||||||||
| * Optional. Deprecation details. Set to an array to mark the ability as deprecated. At least one | ||||||||||||||||||||||||||||||||||||||
| * supported detail must be provided. Deprecated abilities remain available by exact name and can | ||||||||||||||||||||||||||||||||||||||
| * be explicitly included or excluded from discovery through meta filtering. Default false. | ||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
| * @type string $since Optional. Version of the ability provider that deprecated the ability. | ||||||||||||||||||||||||||||||||||||||
| * @type string $replacement Optional. Namespaced ability to use instead. | ||||||||||||||||||||||||||||||||||||||
| * @type string $message Optional. Additional migration guidance. | ||||||||||||||||||||||||||||||||||||||
| * } | ||||||||||||||||||||||||||||||||||||||
| * @type bool $show_in_rest Optional. Whether to expose this ability in the REST API. | ||||||||||||||||||||||||||||||||||||||
| * Default is the value of `$public` when set, false otherwise. | ||||||||||||||||||||||||||||||||||||||
| * } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -140,6 +140,7 @@ class WP_Ability { | |
| * | ||
| * @since 6.9.0 | ||
| * @since 7.1.0 Added the `public` meta argument. | ||
| * @since 7.2.0 Added the `deprecated` meta property. | ||
| * | ||
| * @see wp_register_ability() | ||
| * | ||
|
|
@@ -169,11 +170,20 @@ class WP_Ability { | |
| * @type bool|null $idempotent Optional. If true, calling the ability repeatedly with the same arguments | ||
| * will have no additional effect on its environment. | ||
| * } | ||
| * @type bool $public Optional. Whether the ability is meant to be available | ||
| * to clients such as the REST API, MCP, or AI agents. | ||
| * Seeds the default for per-channel flags like | ||
| * `$show_in_rest`. Defaults to false. | ||
| * @type bool $show_in_rest Optional. Whether to expose this ability in the REST API. | ||
| * @type bool $public Optional. Whether the ability is meant to be available | ||
| * to clients such as the REST API, MCP, or AI agents. | ||
| * Seeds the default for per-channel flags like | ||
| * `$show_in_rest`. Defaults to false. | ||
| * @type false|array<string, string> $deprecated { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| * Optional. Deprecation details. Set to an array to mark the ability as deprecated. At least one | ||
| * supported detail must be provided. Deprecated abilities remain available by exact name and can | ||
| * be explicitly included or excluded from discovery through meta filtering. Default false. | ||
| * | ||
| * @type string $since Optional. Version of the ability provider that deprecated the ability. | ||
| * @type string $replacement Optional. Namespaced ability to use instead. | ||
| * @type string $message Optional. Additional migration guidance. | ||
| * } | ||
| * @type bool $show_in_rest Optional. Whether to expose this ability in the REST API. | ||
| * Default is the value of `$public` when set, false otherwise. | ||
| * } | ||
| * } | ||
|
|
@@ -211,6 +221,7 @@ public function __construct( string $name, array $args ) { | |
| * | ||
| * @since 6.9.0 | ||
| * @since 7.1.0 Added the `public` meta argument. | ||
| * @since 7.2.0 Added support for the `deprecated` meta property. | ||
| * | ||
| * @see WP_Abilities_Registry::register() | ||
| * | ||
|
|
@@ -239,11 +250,20 @@ public function __construct( string $name, array $args ) { | |
| * @type bool|null $idempotent Optional. If true, calling the ability repeatedly with the same arguments | ||
| * will have no additional effect on its environment. | ||
| * } | ||
| * @type bool $public Optional. Whether the ability is meant to be available | ||
| * to clients such as the REST API, MCP, or AI agents. | ||
| * Seeds the default for per-channel flags like | ||
| * `$show_in_rest`. Defaults to false. | ||
| * @type bool $show_in_rest Optional. Whether to expose this ability in the REST API. | ||
| * @type bool $public Optional. Whether the ability is meant to be available | ||
| * to clients such as the REST API, MCP, or AI agents. | ||
| * Seeds the default for per-channel flags like | ||
| * `$show_in_rest`. Defaults to false. | ||
| * @type false|array<string, string> $deprecated { | ||
| * Optional. Deprecation details. Set to an array to mark the ability as deprecated. At least one | ||
| * supported detail must be provided. Deprecated abilities remain available by exact name and can | ||
| * be explicitly included or excluded from discovery through meta filtering. Default false. | ||
| * | ||
| * @type string $since Optional. Version of the ability provider that deprecated the ability. | ||
| * @type string $replacement Optional. Namespaced ability to use instead. | ||
| * @type string $message Optional. Additional migration guidance. | ||
| * } | ||
| * @type bool $show_in_rest Optional. Whether to expose this ability in the REST API. | ||
| * Default is the value of `$public` when set, false otherwise. | ||
| * } | ||
| * } | ||
|
|
@@ -272,10 +292,17 @@ public function __construct( string $name, array $args ) { | |
| * @type bool|null $idempotent If true, calling the ability repeatedly with the same arguments | ||
| * will have no additional effect on its environment. | ||
| * } | ||
| * @type bool $public Whether the ability is meant to be available to clients | ||
| * such as the REST API, MCP, or AI agents. Defaults to | ||
| * false. | ||
| * @type bool $show_in_rest Whether to expose this ability in the REST API. | ||
| * @type bool $public Whether the ability is meant to be available to clients | ||
| * such as the REST API, MCP, or AI agents. Defaults to | ||
| * false. | ||
| * @type false|array<string, string> $deprecated { | ||
| * Deprecation details, or false when the ability is not deprecated. | ||
| * | ||
| * @type string $since Optional. Version of the ability provider that deprecated the ability. | ||
| * @type string $replacement Optional. Namespaced ability to use instead. | ||
|
gziolo marked this conversation as resolved.
|
||
| * @type string $message Optional. Additional migration guidance. | ||
| * } | ||
| * @type bool $show_in_rest Whether to expose this ability in the REST API. | ||
| * } | ||
| * } | ||
| * @throws InvalidArgumentException if an argument is invalid. | ||
|
|
@@ -351,14 +378,57 @@ protected function prepare_properties( array $args ): array { | |
| ); | ||
| } | ||
|
|
||
| if ( isset( $args['meta']['deprecated'] ) && false !== $args['meta']['deprecated'] ) { | ||
| if ( ! is_array( $args['meta']['deprecated'] ) ) { | ||
| throw new InvalidArgumentException( | ||
| __( 'The ability meta should provide `deprecated` as false or an array of deprecation details.' ) | ||
| ); | ||
| } | ||
|
|
||
| $has_deprecation_details = false; | ||
| foreach ( array( 'since', 'replacement', 'message' ) as $key ) { | ||
| if ( ! array_key_exists( $key, $args['meta']['deprecated'] ) ) { | ||
| continue; | ||
| } | ||
|
|
||
| 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 | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| if ( 'replacement' === $key && ! preg_match( '/^[a-z0-9-]+\/[a-z0-9-]+$/', $args['meta']['deprecated'][ $key ] ) ) { | ||
| throw new InvalidArgumentException( | ||
| __( 'The ability deprecation `replacement` value should be a namespaced ability name, i.e. "my-plugin/my-ability". It can only contain lowercase alphanumeric characters, dashes and the forward slash.' ) | ||
| ); | ||
| } | ||
|
Comment on lines
+404
to
+408
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please revert this. Even beyond #10507 (comment), it's a waste of regex. At least a |
||
|
|
||
| $has_deprecation_details = true; | ||
| } | ||
|
|
||
| if ( ! $has_deprecation_details ) { | ||
| throw new InvalidArgumentException( | ||
| __( 'The ability deprecation details should provide at least one of `since`, `replacement`, or `message`.' ) | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| // Set defaults for optional meta. | ||
| $args['meta'] = wp_parse_args( | ||
| $args['meta'] ?? array(), | ||
| array( | ||
| 'annotations' => static::$default_annotations, | ||
| 'deprecated' => false, | ||
| ) | ||
| ); | ||
|
|
||
| // Treat a null `deprecated` value as unset. | ||
| $args['meta']['deprecated'] = $args['meta']['deprecated'] ?? false; | ||
|
|
||
| $args['meta']['annotations'] = wp_parse_args( | ||
| $args['meta']['annotations'], | ||
| static::$default_annotations | ||
|
|
@@ -767,6 +837,7 @@ protected function validate_output( $output ) { | |
| * @since 6.9.0 | ||
| * @since 7.1.0 Added the `wp_ability_invoked` action. | ||
| * @since 7.1.0 Added the `wp_pre_execute_ability` filter. | ||
| * @since 7.2.0 Added deprecation notices for abilities with the `deprecated` meta property. | ||
| * | ||
| * @param mixed $input Optional. The input data for the ability. Default `null`. | ||
| * @return mixed|WP_Error The result of the ability execution, or WP_Error on failure. | ||
|
|
@@ -787,6 +858,16 @@ public function execute( $input = null ) { | |
| */ | ||
| do_action( 'wp_ability_invoked', $this->name, $input, $this ); | ||
|
|
||
| $deprecated = $this->get_meta_item( 'deprecated', false ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| if ( is_array( $deprecated ) ) { | ||
| _deprecated_ability( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per #10507 (comment), I'm seeing no reason why _deprecated_ability() |
||
| $this->name, | ||
| $deprecated['since'] ?? '', | ||
| $deprecated['replacement'] ?? '', | ||
| $deprecated['message'] ?? '' | ||
| ); | ||
| } | ||
|
|
||
| $pre_execute_sentinel = new WP_Filter_Sentinel(); | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason to default this to
false? Considering we support WP7.4+, IMO much better to make this nullable, so a signature can strict-type it as: ?arraysince union return types aren't supported until 8.0.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless it's an important "WordPress way" thing, I agree with returning
nullinstead offalse.