WP_Hook::build_preinitialized_hooks()
Normalizes filters set up before WordPress has initialized to WP_Hook objects.
The $filters parameter should be an array keyed by hook name, with values containing either:
- A WP_Hook instance
- An array of callbacks keyed by their priorities
Examples:
$filters = array( 'wp_fatal_error_handler_enabled' => array( 10 => array( array( 'accepted_args' => 0, 'function' => function() { return false; }, ), ), ), );
Method of the class: WP_Hook{}
No Hooks.
Return
WP_Hook[]
. Array of normalized filters.
Usage
$result = WP_Hook::build_preinitialized_hooks( $filters );
- $filters(array) (required)
- Filters to normalize. See documentation above for details.
Changelog
Since 4.7.0 | Introduced. |
WP_Hook::build_preinitialized_hooks() WP Hook::build preinitialized hooks code WP 6.7.1
public static function build_preinitialized_hooks( $filters ) { /** @var WP_Hook[] $normalized */ $normalized = array(); foreach ( $filters as $hook_name => $callback_groups ) { if ( $callback_groups instanceof WP_Hook ) { $normalized[ $hook_name ] = $callback_groups; continue; } $hook = new WP_Hook(); // Loop through callback groups. foreach ( $callback_groups as $priority => $callbacks ) { // Loop through callbacks. foreach ( $callbacks as $cb ) { $hook->add_filter( $hook_name, $cb['function'], $priority, $cb['accepted_args'] ); } } $normalized[ $hook_name ] = $hook; } return $normalized; }