apply_filters_ref_array

函数
apply_filters_ref_array ( $hook_name, $args )
参数
  • (string) $hook_name The name of the filter hook.
    Required:
  • (array) $args The arguments supplied to the functions hooked to `$hook_name`.
    Required:
返回值
  • (mixed) The filtered value after all hooked functions are applied to it.
相关
  • apply_filters()
定义位置
相关方法
apply_filtersapply_filters_deprecateddo_action_ref_arraywp_is_numeric_arraywp_filter_kses
引入
3.0.0
弃用
-

apply_filters_ref_array: 这个函数与apply_filters相似,但它允许开发者向过滤器函数传递一个参数数组,而不是单个参数。在处理需要多个参数的过滤器时,这很有用。

调用已经添加到过滤器钩子中的回调函数,在一个数组中指定参数。

function apply_filters_ref_array( $hook_name, $args ) {
	global $wp_filter, $wp_filters, $wp_current_filter;

	if ( ! isset( $wp_filters[ $hook_name ] ) ) {
		$wp_filters[ $hook_name ] = 1;
	} else {
		++$wp_filters[ $hook_name ];
	}

	// Do 'all' actions first.
	if ( isset( $wp_filter['all'] ) ) {
		$wp_current_filter[] = $hook_name;
		$all_args            = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
		_wp_call_all_hook( $all_args );
	}

	if ( ! isset( $wp_filter[ $hook_name ] ) ) {
		if ( isset( $wp_filter['all'] ) ) {
			array_pop( $wp_current_filter );
		}

		return $args[0];
	}

	if ( ! isset( $wp_filter['all'] ) ) {
		$wp_current_filter[] = $hook_name;
	}

	$filtered = $wp_filter[ $hook_name ]->apply_filters( $args[0], $args );

	array_pop( $wp_current_filter );

	return $filtered;
}

常见问题

FAQs
查看更多 >