Documentation

WPHookHelper

FinalYes

Helper utilities for recognizing functions related to the WP Hook mechanism.

Tags
since
3.0.0

The property in this class was previously contained in the WordPressCS\WordPress\Sniff class and has been moved here.

Table of Contents

Properties

$hookInvokeFunctions  : array<string, array<string, int|string|array<string|int, string>>>
A list of functions that invoke WP hooks (filters/actions).

Methods

get_functions()  : array<string, bool>
Retrieve a list of the WordPress functions which invoke hooks.
get_hook_name_param()  : array<string|int, mixed>|false
Retrieve the parameter information for the hook name parameter from a stack of parameters passed to one of the WP hook functions.

Properties

$hookInvokeFunctions

A list of functions that invoke WP hooks (filters/actions).

private static array<string, array<string, int|string|array<string|int, string>>> $hookInvokeFunctions = array('do_action' => array('position' => 1, 'name' => 'hook_name'), 'do_action_ref_array' => array('position' => 1, 'name' => 'hook_name'), 'do_action_deprecated' => array('position' => 1, 'name' => 'hook_name'), 'apply_filters' => array('position' => 1, 'name' => 'hook_name'), 'apply_filters_ref_array' => array('position' => 1, 'name' => 'hook_name'), 'apply_filters_deprecated' => array('position' => 1, 'name' => 'hook_name'))

Function name as key, array with target parameter position and name(s) as value.

Tags
since
0.10.0
since
0.11.0

Changed from public static to protected non-static.

since
3.0.0
  • Moved from the Sniff class to this class.
  • The property visibility has changed from protected to private static. Use the get_functions() method for access.
  • The format of the value has changed from a non-relevant boolean to an array with the parameter position and name(s) for the hook name parameter.

Methods

get_functions()

Retrieve a list of the WordPress functions which invoke hooks.

public static get_functions([bool $include_deprecated = true ]) : array<string, bool>
Parameters
$include_deprecated : bool = true

Whether to include the names of functions which are used to invoke deprecated hooks. Defaults to true.

Tags
since
3.0.0
Return values
array<string, bool>

Array with the function names as keys. The value is irrelevant.

get_hook_name_param()

Retrieve the parameter information for the hook name parameter from a stack of parameters passed to one of the WP hook functions.

public static get_hook_name_param(string $function_name, array<string|int, mixed> $parameters) : array<string|int, mixed>|false
Parameters
$function_name : string

The name of the WP hook function which the parameters were passed to.

$parameters : array<string|int, mixed>

The output of a previous call to PassedParameters::getParameters().

Tags
since
3.0.0
Return values
array<string|int, mixed>|false

Array with information on the parameter at the specified offset, or with the specified name. Or FALSE if the specified parameter is not found. See the PHPCSUtils PassedParameters::getParameters() documentation for the format of the returned (single-dimensional) array.


        
On this page

Search results