Changeset 61390
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/abilities-api/class-wp-ability.php
r61086 r61390 278 278 } 279 279 280 if ( empty( $args['execute_callback'] ) || ! is_callable( $args['execute_callback'] ) ) { 280 // If we are not overriding `ability_class` parameter during instantiation, then we need to validate the execute_callback. 281 if ( get_class( $this ) === self::class && ( empty( $args['execute_callback'] ) || ! is_callable( $args['execute_callback'] ) ) ) { 281 282 throw new InvalidArgumentException( 282 283 __( 'The ability properties must contain a valid `execute_callback` function.' ) … … 284 285 } 285 286 286 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'] ) ) ) { 287 289 throw new InvalidArgumentException( 288 290 __( 'The ability properties must provide a valid `permission_callback` function.' ) -
trunk/tests/phpunit/tests/abilities-api/wpAbilitiesRegistry.php
r61364 r61390 24 24 */ 25 25 public function set_up(): void { 26 require_once DIR_TESTDATA . '/../includes/class-tests-custom-ability-class.php'; 27 26 28 parent::set_up(); 27 29 … … 259 261 260 262 /** 263 * Should allow ability registration with custom ability_class that overrides do_execute. 264 * 265 * @ticket 64407 266 * 267 * @covers WP_Abilities_Registry::register 268 * @covers WP_Ability::prepare_properties 269 */ 270 public function test_register_with_custom_ability_class_without_execute_callback() { 271 // Remove execute_callback and permission_callback since the custom class provides its own implementation. 272 unset( self::$test_ability_args['execute_callback'] ); 273 unset( self::$test_ability_args['permission_callback'] ); 274 275 self::$test_ability_args['ability_class'] = 'Tests_Custom_Ability_Class'; 276 277 $result = $this->registry->register( self::$test_ability_name, self::$test_ability_args ); 278 279 $this->assertInstanceOf( WP_Ability::class, $result, 'Should return a WP_Ability instance.' ); 280 $this->assertInstanceOf( Tests_Custom_Ability_Class::class, $result, 'Should return an instance of the custom class.' ); 281 282 // Verify the custom execute method works. 283 $execute_result = $result->execute( 284 array( 285 'a' => 5, 286 'b' => 3, 287 ) 288 ); 289 $this->assertSame( 15, $execute_result, 'Custom do_execute should multiply instead of add.' ); 290 } 291 292 /** 261 293 * Should reject ability registration without an execute callback. 262 294 *
Note: See TracChangeset
for help on using the changeset viewer.