Hook (Action/Filter) API
The Hook system is the backbone of AIPostify's extensibility. It follows a WordPress-familiar pattern of Actions (fire-and-forget events) and Filters (value-modifying pipelines).
📍 Source: App\CMS\Hooks\Hook — This is a facade/static class providing the global hook registry.
Core Methods
Hook::listen()
Register a callback for a named hook point. Works for both actions and filters.
Hook::listen(string $hook, callable $callback, int $priority = 10, bool $requiresAuth = true, ?string $rateLimit = null): void
| Parameter | Type | Description |
|---|---|---|
$hook | string | The hook name (e.g., 'after_post_content' or 'plugin_ajax_{action}') |
$callback | callable | Your callback function or closure |
$priority | int | Execution order (lower = earlier, default: 10) |
$requiresAuth | bool | Whether session auth & CSRF are required (for AJAX/webhook actions, default: true) |
$rateLimit | ?string | Optional rate limit string (e.g., '10,1' for 10 reqs/min) |
🔌 Specialized Action Handlers: When registering action hooks starting with plugin_ajax_, Hook::listen() accepts the optional $requiresAuth and $rateLimit parameters to create secure AJAX and public Webhook endpoints. See the AJAX & Webhook Handlers Documentation for full details.
// Example: Add a footer credit to every post
Hook::listen('after_post_content', function (string $content): string {
return $content . '<p class="credit">Powered by AIPostify</p>';
}, priority: 20);
Hook::fire()
Trigger all listeners registered for a hook name (Action pattern). Returns void — listeners cannot modify a return value.
Hook::fire(string $hook, mixed ...$args): void
// Core fires this after saving a post:
Hook::fire('after_post_save', $post);
// Your plugin listens:
Hook::listen('after_post_save', function ($post) {
\Log::info("Post #{$post->id} saved: {$post->title}");
});
Hook::filter()
Alias for Hook::listen() — semantically marks a callback as a filter (expects the callback to return a modified value).
Hook::filter(string $hook, callable $callback, int $priority = 10): void
Hook::filter('the_title', function (string $title): string {
return '🔖 ' . $title;
});
Hook::applyFilters()
Pass a value through all registered filter callbacks for a hook name. Each callback receives the output of the previous one.
$result = Hook::applyFilters(string $hook, mixed $value, mixed ...$args): mixed
// Core uses this to filter post content before display:
$content = Hook::applyFilters('the_content', $post->content, $post);
// Your plugin registered a filter on 'the_content':
Hook::filter('the_content', function ($content, $post) {
if ($post->type === 'announcement') {
return '<div class="alert">' . $content . '</div>';
}
return $content;
});
WordPress-Style Aliases
AIPostify provides global function aliases that mirror WordPress's hook API for developers familiar with that ecosystem:
| WordPress-style | AIPostify Equivalent |
|---|---|
add_action($hook, $cb, $priority) | Hook::listen($hook, $cb, $priority) |
add_filter($hook, $cb, $priority) | Hook::filter($hook, $cb, $priority) |
do_action($hook, ...$args) | Hook::fire($hook, ...$args) |
apply_filters($hook, $value, ...$args) | Hook::applyFilters($hook, $value, ...$args) |
// These two are equivalent:
add_action('init', function () {
// Plugin initialization code
});
Hook::listen('init', function () {
// Plugin initialization code
});
Known Core Hook Points
These hooks are fired by AIPostify core at specific lifecycle moments:
| Hook Name | Type | Fired When | Arguments |
|---|---|---|---|
init | Action | Core initialization complete | — |
admin_menu | Action | Admin sidebar menu being built | — |
after_post_save | Action | A post has been saved/updated | $post |
before_post_delete | Action | Just before a post is deleted | $post |
the_content | Filter | Post content rendered for display | $content, $post |
the_title | Filter | Post title rendered for display | $title, $post |
after_post_content | Filter | Appended after post content | $content |
head | Action | HTML <head> section being rendered | — |
footer | Action | Just before </body> | — |
wp_enqueue_scripts | Action | Front-end asset enqueueing | — |
admin_enqueue_scripts | Action | Admin panel asset enqueueing | — |
💡 Tip: You can define your own custom hook points using Hook::fire('my_custom_hook', $data) — other plugins can then listen to your hooks for interoperability.
Last verified against AIPostify core. © 2026 AIPostify Marketplace Developer Documentation.