CallbackUtil
in package
Utility class for working with WordPress hooks and callbacks.
Tags
Table of Contents
- get_callback_signature() : string
- Get a stable signature for a callback that can be used for hashing.
- get_hook_callback_signatures() : array<int, array<string|int, string>>
- Get signatures for all callbacks attached to a specific hook.
- get_closure_signature() : string
- Get a stable signature for a closure based on its file path and line numbers.
- get_invokable_signature() : string
- Get a stable signature for an invokable object based on its class and __invoke method location.
Methods
get_callback_signature()
Get a stable signature for a callback that can be used for hashing.
public
static get_callback_signature(callable|mixed $callback) : string
This method normalizes callbacks into consistent string representations, regardless of changes in dynamic properties in callback instances.
Parameters
- $callback : callable|mixed
-
A PHP callback.
Tags
Return values
string — Normalized callback signature.get_hook_callback_signatures()
Get signatures for all callbacks attached to a specific hook.
public
static get_hook_callback_signatures(string $hook_name) : array<int, array<string|int, string>>
Returns an array of callback signatures for all callbacks registered with the specified hook name, organized by priority. This is useful for generating cache keys or comparing hook state.
Closure signatures are based on their file location and line numbers, providing consistent hashes across requests for the same closure code.
Parameters
- $hook_name : string
-
The name of the hook to inspect.
Tags
Return values
array<int, array<string|int, string>> — Array of priority => array( signatures ), empty if hook has no callbacks.get_closure_signature()
Get a stable signature for a closure based on its file path and line numbers.
private
static get_closure_signature(Closure $closure) : string
Parameters
- $closure : Closure
-
The closure to generate a signature for.
Tags
Return values
string — Signature in the format 'Closure@filename:startLine-endLine'.get_invokable_signature()
Get a stable signature for an invokable object based on its class and __invoke method location.
private
static get_invokable_signature(object $invokable) : string
For regular classes, returns 'ClassName::__invoke' since the class name is stable. For anonymous classes, includes file location since the class name varies between requests.
Parameters
- $invokable : object
-
The invokable object to generate a signature for.
