Commit c3ad8bbe52 for wordpress.org
commit c3ad8bbe524455e761891c72176738cb75768e16
Author: jorgefilipecosta <jorgefilipecosta@git.wordpress.org>
Date: Wed Dec 17 15:29:38 2025 +0000
Abilities API: Enhance WP_Ability validation for execute_callback and permission_callback.
Abilities API allows for extending WP_Ability by providing ability_class during the ability registration. This is meant to unlock complex abilities holding some sort of state or logic that requires multiple helper methods.
In all of those scenarios you would ovewrite execute or do_execute method.
However, because the check for execute_callback is in constructor, then in order to register an ability with ability_class overwrite, you have to BOTH: provide do_execute and provide a dummy execute_callback. The same need happens for permission_callback.
This commit fixes the issue execute_callback and permission_callback are now optional when a class is provided.
Props artpi, swissspidy, jorgefilipecosta, mindctrl.
Fixes #64407.
Built from https://develop.svn.wordpress.org/trunk@61390
git-svn-id: http://core.svn.wordpress.org/trunk@60702 1a063a9b-81f0-0310-95a4-ce76da25c4cd
diff --git a/wp-includes/abilities-api/class-wp-ability.php b/wp-includes/abilities-api/class-wp-ability.php
index d116080c1c..3af7f7fc98 100644
--- a/wp-includes/abilities-api/class-wp-ability.php
+++ b/wp-includes/abilities-api/class-wp-ability.php
@@ -277,13 +277,15 @@ class WP_Ability {
);
}
- if ( empty( $args['execute_callback'] ) || ! is_callable( $args['execute_callback'] ) ) {
+ // If we are not overriding `ability_class` parameter during instantiation, then we need to validate the execute_callback.
+ if ( get_class( $this ) === self::class && ( empty( $args['execute_callback'] ) || ! is_callable( $args['execute_callback'] ) ) ) {
throw new InvalidArgumentException(
__( 'The ability properties must contain a valid `execute_callback` function.' )
);
}
- if ( empty( $args['permission_callback'] ) || ! is_callable( $args['permission_callback'] ) ) {
+ // If we are not overriding `ability_class` parameter during instantiation, then we need to validate the permission_callback.
+ if ( get_class( $this ) === self::class && ( empty( $args['permission_callback'] ) || ! is_callable( $args['permission_callback'] ) ) ) {
throw new InvalidArgumentException(
__( 'The ability properties must provide a valid `permission_callback` function.' )
);
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 7d5071b192..9628569fc6 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '7.0-alpha-61389';
+$wp_version = '7.0-alpha-61390';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.