Automattic\WooCommerce\Utilities

CallbackUtil::get_hook_callback_signaturespublic staticWC 10.5.0

Get signatures for all callbacks attached to a specific hook.

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.

Method of the class: CallbackUtil{}

No Hooks.

Returns

Array. array<string>> Array of priority => array( signatures ), empty if hook has no callbacks.

Usage

$result = CallbackUtil::get_hook_callback_signatures( $hook_name ): array;
$hook_name(string) (required)
The name of the hook to inspect.

Changelog

Since 10.5.0 Introduced.

CallbackUtil::get_hook_callback_signatures() code WC 11.0.1

public static function get_hook_callback_signatures( string $hook_name ): array {
	global $wp_filter;

	if ( ! isset( $wp_filter[ $hook_name ] ) ) {
		return array();
	}

	$result = array();

	foreach ( $wp_filter[ $hook_name ]->callbacks as $priority => $priority_callbacks ) {
		$result[ $priority ] = array_map(
			fn( $callback_data ) => self::get_callback_signature( $callback_data['function'] ),
			array_values( $priority_callbacks )
		);
	}

	return $result;
}