Skip to content

Commit 5f091d0

Browse files
committed
Make the permission callback optional too for ability class
1 parent d8a71e5 commit 5f091d0

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/wp-includes/abilities-api/class-wp-ability.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ protected function prepare_properties( array $args ): array {
284284
);
285285
}
286286

287-
if ( empty( $args['permission_callback'] ) || ! is_callable( $args['permission_callback'] ) ) {
287+
// If we are not overriding `ability_class` parameter during instantiation, then we need to validate the permission_callback.
288+
if ( get_class( $this ) === self::class && ( empty( $args['permission_callback'] ) || ! is_callable( $args['permission_callback'] ) ) ) {
288289
throw new InvalidArgumentException(
289290
__( 'The ability properties must provide a valid `permission_callback` function.' )
290291
);

tests/phpunit/tests/abilities-api/wpAbilitiesRegistry.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,9 @@ public function test_register_incorrect_execute_callback_type() {
268268
* @covers WP_Ability::prepare_properties
269269
*/
270270
public function test_register_with_custom_ability_class_without_execute_callback() {
271-
// Remove execute_callback since the custom class provides its own implementation.
271+
// Remove execute_callback and permission_callback since the custom class provides its own implementation.
272272
unset( self::$test_ability_args['execute_callback'] );
273+
unset( self::$test_ability_args['permission_callback'] );
273274

274275
self::$test_ability_args['ability_class'] = 'Tests_Custom_Ability_Class';
275276

0 commit comments

Comments
 (0)