Cherry Blossom feature
Framework Traits: Hooks trait
Provides hook registration and theme-owned dispatch helpers.
Provides hook registration and theme-owned dispatch helpers.
Capabilities and extension points
Provides hook registration and theme-owned dispatch helpers.
Pass unprefixed theme names to do_action() and apply_filters(); they add hook_base. Registration and removal helpers pass names verbatim, so use the complete public hook name, including any theme or plugin prefix.
Creates an object-method callback array.
Callers must supply the name of an existing public method when the returned array needs to be callable.
- param string $callback Method name.
- return array{0: object, 1: string} Object-method callback array.
Registers an object method on one or more action hooks.
Hook names are passed verbatim; include the theme prefix when registering a theme-owned hook. The callback must be callable by WordPress.
- param string|string[] $hook Full hook name or names.
- param string $callback Method name on the current object.
- param int $priority Optional. Hook priority. Default 10.
- param int $accepted_args Optional. Callback argument limit. Default 1.
Registers an object method on one or more filter hooks.
Hook names are passed verbatim; include the theme prefix when registering a theme-owned hook. The callback must be callable by WordPress.
- param string|string[] $hook Full hook name or names.
- param string $callback Method name on the current object.
- param int $priority Optional. Hook priority. Default 10.
- param int $accepted_args Optional. Callback argument limit. Default 2.
Removes an object method on one or more action hooks.
Hook names are passed verbatim; include the theme prefix when registering a theme-owned hook. The callback must be callable by WordPress. Removal must use the same method and priority as registration.
- param string|string[] $hook Full hook name or names.
- param string $callback Method name on the current object.
- param int $priority Optional. Hook priority. Default 10.
Removes an object method on one or more filter hooks.
Hook names are passed verbatim; include the theme prefix when registering a theme-owned hook. The callback must be callable by WordPress. Removal must use the same method and priority as registration.
- param string|string[] $hook Full hook name or names.
- param string $callback Method name on the current object.
- param int $priority Optional. Hook priority. Default 10.
Registers an AJAX method for the selected login states.
The default 'both' registers wp_ajax_ and wp_ajax_nopriv_ handlers so a frontend feature works before and after login. Use 'logged-in' for only authenticated requests or 'logged-out' for only guest requests.
The callback must be public and owns nonce, capability and input checks. Selecting 'logged-in' checks authentication only; it does not grant or verify permission to perform the requested operation. Invalid access values throw before either hook is registered.
- param string $callback Method name and AJAX action suffix.
- param string $access Optional. 'both', 'logged-in' or 'logged-out'. Default 'both'.
- throws \InvalidArgumentException When the access value is unsupported.
Dispatches one or more theme-owned actions in the supplied order.
- param array|string $tags Hook(s) to run. Multiple accepted.
- param mixed …$args Optional arguments passed to each action.
Passes a value through one or more theme-owned filters in order.
Each result becomes the input to the next hook. An empty list returns the original value. Short names receive hook_base; already-prefixed names are accepted without adding the prefix twice.
- param array|string $tags Hooks to run.
- param mixed $value Value to be modified.
- param mixed …$args Optional arguments passed to each filter.
- return mixed Filtered return value.
Prefixes a theme-owned hook when it is not already qualified.
- param string $tag Hook name.
- return string Qualified hook name.
Source reference
This editable reference page is based on the PHP documentation in framework/traits/wordpress/trait-hooks.php.