Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Feb 5, 2026. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 55
feat!: make permission_callback arg required#73
Merged
gziolo
merged 6 commits into
WordPress:trunk
from
justlevine:feat/require-permission_callbackSep 23, 2025
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b99744c
feat!: make `permission_callback` arg required
justlevine 4d7ba35
Update tests/unit/abilities-api/wpAbilitiesRegistry.php
justlevine b08da61
tests: add WP_Ability::prepare_properties to coverage
justlevine c99eaae
Merge branch 'trunk' into feat/require-permission_callback
justlevine 00d5099
Update includes/abilities-api/class-wp-ability.php
gziolo a1b27ab
Merge branch 'trunk' into feat/require-permission_callback
gziolo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -46,18 +46,17 @@ final class WP_Abilities_Registry { | ||
| * @param string $name The name of the ability. The name must be a string containing a namespace | ||
| * prefix, i.e. `my-plugin/my-ability`. It can only contain lowercase | ||
| * alphanumeric characters, dashes and the forward slash. | ||
| * @param array<string,mixed> $args An associative array of arguments for the ability. This should include | ||
justlevine marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| * `label`, `description`, `input_schema`, `output_schema`, | ||
| * `execute_callback`, `permission_callback`, `meta`, and ability_class. | ||
| * @param array<string,mixed> $args An associative array of arguments for the ability. See wp_register_ability() for | ||
| * details. | ||
| * @return ?\WP_Ability The registered ability instance on success, null on failure. | ||
| * | ||
| * @phpstan-param array{ | ||
| * label?: string, | ||
| * description?: string, | ||
| * execute_callback?: callable( mixed $input= ): (mixed|\WP_Error), | ||
| * permission_callback?: callable( mixed $input= ): (bool|\WP_Error), | ||
| * input_schema?: array<string,mixed>, | ||
| * output_schema?: array<string,mixed>, | ||
| * execute_callback?: callable( mixed $input= ): (mixed|\WP_Error), | ||
| * permission_callback?: ?callable( mixed $input= ): (bool|\WP_Error), | ||
| * meta?: array<string,mixed>, | ||
| * ability_class?: class-string<\WP_Ability>, | ||
| * ...<string, mixed> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
justlevine marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -703,38 +703,6 @@ public function test_ability_without_type_defaults_to_tool(): void { | ||
| $this->assertEquals( 200, $post_response->get_status() ); | ||
| } | ||
| /** | ||
| * Test permission check with null permission callback. | ||
| */ | ||
| public function test_permission_check_passes_when_callback_not_set(): void { | ||
justlevine marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| // Register ability without permission callback. | ||
| wp_register_ability( | ||
| 'test/no-permission-callback', | ||
| array( | ||
| 'label' => 'No Permission Callback', | ||
| 'description' => 'Ability without permission callback', | ||
| 'execute_callback' => static function () { | ||
| return array( 'executed' => true ); | ||
| }, | ||
| 'meta' => array( 'type' => 'tool' ), | ||
| // No permission_callback set | ||
| ) | ||
| ); | ||
| wp_set_current_user( 0 ); // Not logged in | ||
| $request = new WP_REST_Request( 'POST', '/wp/v2/abilities/test/no-permission-callback/run' ); | ||
| $request->set_header( 'Content-Type', 'application/json' ); | ||
| $response = $this->server->dispatch( $request ); | ||
| // Should succeed when no permission callback is set | ||
| $this->assertEquals( 200, $response->get_status() ); | ||
| // Restore user for other tests | ||
| wp_set_current_user( self::$user_id ); | ||
| } | ||
| /** | ||
| * Test edge case with empty input for both GET and POST. | ||
| */ | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.