Skip to content

Commit 3ad7a38

Browse files
authored
Propose filters to use with the registered ability (#47)
1 parent 7b10f5e commit 3ad7a38

File tree

9 files changed

+19
-12
lines changed

9 files changed

+19
-12
lines changed

includes/abilities-api.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* @package WordPress
88
* @subpackage Abilities API
99
* @since 0.1.0
10+
*
11+
* phpcs:disable WordPress.NamingConventions.PrefixAllGlobals
1012
*/
1113

1214
declare( strict_types = 1 );
@@ -34,7 +36,7 @@
3436
* input_schema?: array<string,mixed>,
3537
* output_schema?: array<string,mixed>,
3638
* execute_callback?: callable( array<string,mixed> $input): (mixed|\WP_Error),
37-
* permission_callback?: callable( ?array<string,mixed> $input ): bool,
39+
* permission_callback?: callable( array<string,mixed> $input ): (bool|\WP_Error),
3840
* meta?: array<string,mixed>,
3941
* ability_class?: class-string<\WP_Ability>,
4042
* ...<string, mixed>

includes/abilities-api/class-wp-abilities-registry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ final class WP_Abilities_Registry {
5757
* input_schema?: array<string,mixed>,
5858
* output_schema?: array<string,mixed>,
5959
* execute_callback?: callable( array<string,mixed> $input): (mixed|\WP_Error),
60-
* permission_callback?: ?callable( ?array<string,mixed> $input ): bool,
60+
* permission_callback?: ?callable( array<string,mixed> $input ): (bool|\WP_Error),
6161
* meta?: array<string,mixed>,
6262
* ability_class?: class-string<\WP_Ability>,
6363
* ...<string, mixed>

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ class WP_Ability {
6565
* The ability execute callback.
6666
*
6767
* @since 0.1.0
68-
* @var callable
68+
* @var callable( array<string,mixed> $input): (mixed|\WP_Error)
6969
*/
7070
protected $execute_callback;
7171

7272
/**
7373
* The optional ability permission callback.
7474
*
7575
* @since 0.1.0
76-
* @var ?callable
76+
* @var ?callable( array<string,mixed> $input ): (bool|\WP_Error)
7777
*/
7878
protected $permission_callback = null;
7979

@@ -107,7 +107,7 @@ class WP_Ability {
107107
* input_schema?: array<string,mixed>,
108108
* output_schema?: array<string,mixed>,
109109
* execute_callback: callable( array<string,mixed> $input): (mixed|\WP_Error),
110-
* permission_callback?: ?callable( ?array<string,mixed> $input ): bool,
110+
* permission_callback?: ?callable( array<string,mixed> $input ): (bool|\WP_Error),
111111
* meta?: array<string,mixed>,
112112
* ...<string, mixed>,
113113
* } $properties
@@ -240,7 +240,7 @@ protected function validate_input( array $input = array() ) {
240240
* @since 0.1.0
241241
*
242242
* @param array<string,mixed> $input Optional. The input data for permission checking.
243-
* @return true|\WP_Error Whether the ability has the necessary permission.
243+
* @return bool|\WP_Error Whether the ability has the necessary permission.
244244
*/
245245
public function has_permission( array $input = array() ) {
246246
$is_valid = $this->validate_input( $input );

phpcs.xml.dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
</rule>
6161
<rule ref="WordPress-Extra">
6262
<exclude name="WordPress.WP.I18n.MissingArgDomain" />
63-
<exclude name="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound" />
63+
6464
<!-- Needed to typehint, see: https://github.com/WordPress/WordPress-Coding-Standards/issues/403 -->
6565
<exclude name="Generic.Commenting.DocComment.MissingShort" />
6666
</rule>
@@ -199,7 +199,7 @@
199199
<element value="WP_Ability" />
200200
<element value="WP_Abilities" />
201201
<element value="WP_REST_Abilities" />
202-
<element value="WP_ABILITIES_API" /> <!-- Constant -->
202+
<element value="WP_ABILITIES_API" /><!-- Constant -->
203203
</property>
204204
</properties>
205205
</rule>

tests/bootstrap.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*
55
* @package abilities-api
66
*
7-
* phpcs:disable WordPress.NamingConventions.PrefixAllGlobals
87
* phpcs:disable WordPressVIPMinimum.Files.IncludingFile.UsingVariable
98
*/
109

tests/unit/abilities-api/wpAbilitiesRegistry.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php declare( strict_types=1 );
22

33
/**
4+
* Tests for the abilities registry functionality.
5+
*
46
* @covers WP_Abilities_Registry
57
*
68
* @group abilities-api

tests/unit/abilities-api/wpRegisterAbility.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ protected function do_execute( array $input ) {
1010
}
1111

1212
/**
13+
* Tests for registering, unregistering and retrieving abilities.
14+
*
1315
* @covers wp_register_ability
1416
* @covers wp_unregister_ability
1517
* @covers wp_get_ability
@@ -270,7 +272,7 @@ public function test_execute_ability_no_output_schema_match(): void {
270272
);
271273
$this->assertWPError(
272274
$actual,
273-
'Execution should fail due to output not matching schema.',
275+
'Execution should fail due to output not matching schema.'
274276
);
275277
$this->assertSame( 'ability_invalid_output', $actual->get_error_code() );
276278
$this->assertSame(
@@ -376,8 +378,6 @@ public function test_unregister_existing_ability() {
376378
* Tests retrieving existing ability.
377379
*/
378380
public function test_get_existing_ability() {
379-
global $wp_abilities;
380-
381381
$name = self::$test_ability_name;
382382
$properties = self::$test_ability_properties;
383383
$callback = static function ( $instance ) use ( $name, $properties ) {

tests/unit/rest-api/wpRestAbilitiesListController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php declare( strict_types=1 );
22

33
/**
4+
* Tests for the REST list controller for abilities endpoint.
5+
*
46
* @covers WP_REST_Abilities_List_Controller
57
* @group abilities-api
68
* @group rest-api

tests/unit/rest-api/wpRestAbilitiesRunController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php declare( strict_types=1 );
22

33
/**
4+
* Tests for the REST run controller for abilities endpoint.
5+
*
46
* @covers WP_REST_Abilities_Run_Controller
57
* @group abilities-api
68
* @group rest-api

0 commit comments

Comments
 (0)