Skip to content

Add ActionHook and FilterHook helpers and prefix the view path filter - #23

Merged
ahamed merged 1 commit into
mainfrom
feature/action-filter-hook-helpers
Nov 25, 2026
Merged

ahamed merged 1 commit into
mainfrom
feature/action-filter-hook-helpers

Conversation

@ahamed

@ahamed ahamed commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Add Framework\Wordpress\ActionHook and Framework\Wordpress\FilterHook, static helpers that fire and register WordPress hooks with names that say what the call does:

  • ActionHook::fire() / ActionHook::add() pass through to do_action() / add_action()
  • FilterHook::apply() / FilterHook::add() pass through to apply_filters() / add_filter()

The verbs differ on purpose: apply returns the filtered value, so a filter call without an assignment looks wrong. Each method passes its arguments to the core function unchanged and returns what it returns.

The framework's own hook calls in src/ now go through these helpers. The callback must be callable when it is registered, and priority and accepted-args must be integers, so a HookSubscriber returning a non-integer from get_priority() or get_args_count() now throws a TypeError.

Breaking: the view path filter in TemplateEngine::resolve_path() is renamed from framework/view/path to {prefix}view_path (for example kirki_view_path). The old string was the same for every plugin that bundles the framework, because php-scoper does not prefix string literals, so one plugin's callback also changed another plugin's view paths.

Tests cover both helpers and the prefixed filter. Adds a __return_false stub for the test suite. CHANGELOG (3.3.5), README and docs/routing-examples.md are updated.

Add Framework\Wordpress\ActionHook and Framework\Wordpress\FilterHook, static
helpers that fire and register WordPress hooks with names that say what the
call does:

- ActionHook::fire() / ActionHook::add() pass through to do_action() / add_action()
- FilterHook::apply() / FilterHook::add() pass through to apply_filters() / add_filter()

The verbs differ on purpose: `apply` returns the filtered value, so a filter
call without an assignment looks wrong. Each method passes its arguments to
the core function unchanged and returns what it returns.

The framework's own hook calls in src/ now go through these helpers. The
callback must be callable when it is registered, and priority and
accepted-args must be integers, so a HookSubscriber returning a non-integer
from get_priority() or get_args_count() now throws a TypeError.

Breaking: the view path filter in TemplateEngine::resolve_path() is renamed
from `framework/view/path` to `{prefix}view_path` (for example
`kirki_view_path`). The old string was the same for every plugin that bundles
the framework, because php-scoper does not prefix string literals, so one
plugin's callback also changed another plugin's view paths.

Tests cover both helpers and the prefixed filter. Adds a __return_false stub
for the test suite. CHANGELOG (3.3.5), README and docs/routing-examples.md
are updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ahamed
ahamed merged commit 72c5eed into main Nov 25, 2026
1 check passed
@ahamed
ahamed deleted the feature/action-filter-hook-helpers branch November 25, 2026 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant