Add a WordPress action or filter hook to a plugin or theme.
Add a properly structured WordPress action or filter to the correct class in an existing package.
Ask the user:
add_action or add_filter?save_post, the_content) or a custom hook (e.g. dekodeinteraktiv/plugin/after_save).packages/?Search the target package for:
hooks() method — this is the right place.src/src/Frontend/ContentModifier.php).hooks()public function hooks(): void {
// ... existing hooks ...
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).Filter example:
/**
* Modifies the post content.
*
* @param string $content The original post content.
* @return string The modified content.
*/
public function modify_content( string $content ): string {
if ( ! is_singular( 'post' ) ) {
return $content;
}
// ... apply transformation ...
return $content;
}
Action example:
/**
* Fires after a post is saved.
*
* @param int $post_id Post ID.
* @param \WP_Post $post Post object.
* @param bool $update Whether this is an update.
*/
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;
}
// ... do the work ...
}
When dispatching your own hook (so other code can extend it):
// Action
do_action( 'dekodeinteraktiv/plugin/after_item_created', $item_id, $item_data );
// Filter
$value = apply_filters( 'dekodeinteraktiv/plugin/item_title', $title, $item_id );
Rules:
<org>/<plugin-slug>/ to guarantee uniqueness.do_action / apply_filters.composer lint
composer lint-fix # if needed
composer lint # re-run to confirm clean