remove_filter

函数


remove_filter ( $hook_name, $callback, $priority = 10 )
参数
  • (string)
    $hook_name
    The filter hook to which the function to be removed is hooked.
    Required:
  • (callable|string|array)
    $callback
    The callback to be removed from running when the filter is applied. This function can be called unconditionally to speculatively remove a callback that may or may not exist.
    Required:
  • (int)
    $priority
    Optional. The exact priority used when adding the original filter callback. Default 10.
    Required:
    Default: 10
返回值
  • (bool) Whether the function existed before it was removed.
定义位置
  • wp-includes/plugin.php
    , line 313
引入
1.2.0
弃用

从一个过滤器钩子上删除一个回调函数。

这可以用来移除附加在特定过滤器钩子上的默认函数,并可能用一个替代品来替代它们。

要删除一个钩子,`$callback`和`$priority`参数必须与钩子被添加时相匹配。这对过滤器和动作都适用。移除失败时不会有任何警告。

function remove_filter( $hook_name, $callback, $priority = 10 ) {
	global $wp_filter;

	$r = false;

	if ( isset( $wp_filter[ $hook_name ] ) ) {
		$r = $wp_filter[ $hook_name ]->remove_filter( $hook_name, $callback, $priority );

		if ( ! $wp_filter[ $hook_name ]->callbacks ) {
			unset( $wp_filter[ $hook_name ] );
		}
	}

	return $r;
}