apply_filters()

最后更新于:2021-11-25 19:48:34

apply_filters( string$hook_name, mixed$value)

Calls the callback functions that have been added to a filter hook.

参数

$hook_name

(string) (Required) The name of the filter hook.

$value

(mixed) (Required) The value to filter.

$args

(mixed) (Required) Additional parameters to pass to the callback functions.

响应

(mixed) The filtered value after all hooked functions are applied to it.

源文件

文件: gc-includes/plugin.php

function apply_filters( $hook_name, $value ) {
	global $gc_filter, $gc_current_filter;

	$args = func_get_args();

	// Do 'all' actions first.
	if ( isset( $gc_filter['all'] ) ) {
		$gc_current_filter[] = $hook_name;
		_gc_call_all_hook( $args );
	}

	if ( ! isset( $gc_filter[ $hook_name ] ) ) {
		if ( isset( $gc_filter['all'] ) ) {
			array_pop( $gc_current_filter );
		}

		return $value;
	}

	if ( ! isset( $gc_filter['all'] ) ) {
		$gc_current_filter[] = $hook_name;
	}

	// Don't pass the tag name to GC_Hook.
	array_shift( $args );

	$filtered = $gc_filter[ $hook_name ]->apply_filters( $value, $args );

	array_pop( $gc_current_filter );

	return $filtered;
}