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.
定义位置
相关方法
remove_all_filterskses_remove_filtersremove_rolecurrent_filterremove_rewrite_tag
引入
1.2.0
弃用
-

remove_filter: 这个函数用来删除WordPress中的一个过滤器。过滤器是用来修改WordPress中的数据的: 这个函数需要三个参数:过滤器名称,要删除的回调函数,以及回调函数的优先级。

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

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

要删除一个钩子,`$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;
}

常见问题

FAQs
查看更多 >