-
Notifications
You must be signed in to change notification settings - Fork 20
Add execute actions to the ability object #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+371
−10
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d50f442
Add execute actions to the ability object
gziolo c622a91
Update includes/abilities-api/class-wp-ability.php
gziolo 523f93c
Add WordPress actions for ability execution hooks
gziolo 84eb2b5
Improve code quality
gziolo ca6a230
Update README.md
gziolo 3845992
Address feedback from review
gziolo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# 6. Hooks | ||
|
||
The Abilities API provides [WordPress Action Hooks](https://developer.wordpress.org/apis/hooks/) that allow developers to monitor and respond to ability execution events. | ||
|
||
## Available Actions | ||
|
||
### `before_execute_ability` | ||
|
||
Fires immediately before an ability gets executed, after permission checks have passed but before the execution callback is called. | ||
|
||
```php | ||
/** | ||
* Fires before an ability gets executed. | ||
* | ||
* @since n.e.x.t | ||
* | ||
* @param string $ability_name The name of the ability. | ||
* @param mixed $input The input data for the ability. | ||
*/ | ||
do_action( 'before_execute_ability', $ability_name, $input ); | ||
``` | ||
|
||
**Parameters:** | ||
|
||
- `$ability_name` (`string`): The namespaced name of the ability being executed (e.g., `my-plugin/get-posts`). | ||
- `$input` (`mixed`): The input data passed to the ability. | ||
|
||
### `after_execute_ability` | ||
|
||
Fires immediately after an ability has finished executing successfully, after output validation has passed. | ||
|
||
```php | ||
/** | ||
* Fires immediately after an ability finished executing. | ||
* | ||
* @since n.e.x.t | ||
* | ||
* @param string $ability_name The name of the ability. | ||
* @param mixed $input The input data for the ability. | ||
* @param mixed $result The result of the ability execution. | ||
*/ | ||
do_action( 'after_execute_ability', $ability_name, $input, $result ); | ||
``` | ||
|
||
**Parameters:** | ||
|
||
- `$ability_name` (`string`): The namespaced name of the ability that was executed. | ||
- `$input` (`mixed`): The input data that was passed to the ability. | ||
- `$result` (`mixed`): The validated result returned by the ability's execution callback. | ||
|
||
## Usage Examples | ||
|
||
**Basic Logging** | ||
|
||
```php | ||
// Log all ability executions. | ||
add_action( 'before_execute_ability', function( $ability_name, $input ) { | ||
error_log( 'Executing ability: ' . $ability_name ); | ||
if ( $input !== null ) { | ||
error_log( 'Input: ' . wp_json_encode( $input ) ); | ||
} | ||
}, 10, 2 ); | ||
|
||
add_action( 'after_execute_ability', function( $ability_name, $input, $result ) { | ||
error_log( 'Completed ability: ' . $ability_name ); | ||
error_log( 'Result: ' . wp_json_encode( $result ) ); | ||
}, 10, 3 ); | ||
``` |
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
Oops, something went wrong.
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.