| name | add-hook |
| description | Add a WordPress action or filter hook to a plugin or theme. |
| allowedDomains | ["wordpress.org","developer.wordpress.org"] |
Add a WordPress Hook (Action or Filter)
Add a properly structured WordPress action or filter to the correct class in an existing package.
Step 1 — Gather information
Ask the user:
- Hook type —
add_action or add_filter?
- Hook name — the WordPress hook (e.g.
save_post, the_content) or a custom hook (e.g. dekodeinteraktiv/plugin/after_save).
- Target package — which plugin or theme in
packages/?
- What should it do? — describe the intended behaviour.
Step 2 — Find the right class
Search the target package for:
- A class that already has a
hooks() method — this is the right place.
- If the hook relates to a specific responsibility (Admin, Api, Frontend), find the relevant class in
src/.
- If no suitable class exists, suggest creating a new one (e.g.
src/Frontend/ContentModifier.php).
Step 3 — Implementation pattern
Register in hooks()
public function hooks(): void {
add_filter( 'the_content', [ $this, 'modify_content' ], 20 );
}
Priority guidelines:
10 — default, use when order doesn't matter.
< 10 — must run before core/other plugins.
> 10 — must run after core/other plugins.
PHP_INT_MAX — must run absolutely last (e.g. final output sanitisation).
Implement the callback method
Filter example:
public function modify_content( string $content ): string {
if ( ! is_singular( 'post' ) ) {
return $content;
}
return $content;
}
Action example:
public function after_post_save( int $post_id, \WP_Post $post, bool $update ): void {
if ( wp_is_post_autosave( $post_id ) || wp_is_post_revision( $post_id ) ) {
return;
}
}
Step 4 — Custom hook best practices
When dispatching your own hook (so other code can extend it):
do_action( 'dekodeinteraktiv/plugin/after_item_created', $item_id, $item_data );
$value = apply_filters( 'dekodeinteraktiv/plugin/item_title', $title, $item_id );
Rules:
- Prefix with
<org>/<plugin-slug>/ to guarantee uniqueness.
- Document all custom hooks with a docblock above
do_action / apply_filters.
- Filters must always return a value — even if they do nothing to it.
Step 5 — Verify
composer lint
composer lint-fix
composer lint