remove_filter()

remove_filter( string $tag, callable $function_to_remov…

remove_filter( string $tag, callable $function_to_remove, int $priority = 10 )

从指定的筛选器挂钩中删除函数。
Removes a function from a specified filter hook.

目录锚点:#说明#参数#返回#源码#笔记


说明(Description)

此函数删除附加到指定筛选器挂钩的函数。此方法可用于删除附加到特定筛选器挂钩的默认函数,并可能用替换函数替换它们。


参数(Parameters)

参数 类型 必填 说明
$tag (string) 必需 将要删除的函数挂接到的筛选器挂钩。
$function_to_remove (callable) 必需 应删除的函数的名称。
$priority (int) 可选 函数的优先级。

返回(Return)

(bool)函数在被移除之前是否存在。


源码(Source)

/**
 * Removes a function from a specified filter hook.
 *
 * This function removes a function attached to a specified filter hook. This
 * method can be used to remove default functions attached to a specific filter
 * hook and possibly replace them with a substitute.
 *
 * To remove a hook, the $function_to_remove and $priority arguments must match
 * when the hook was added. This goes for both filters and actions. No warning
 * will be given on removal failure.
 *
 * @since 1.2.0
 *
 * @global array $wp_filter         Stores all of the filters
 * @global array $merged_filters    Merges the filter hooks using this function.
 *
 * @param string   $tag                The filter hook to which the function to be removed is hooked.
 * @param callback $function_to_remove The name of the function which should be removed.
 * @param int      $priority           Optional. The priority of the function. Default 10.
 * @return bool    Whether the function existed before it was removed.
 */
function remove_filter( $tag, $function_to_remove, $priority = 10 ) {
	$function_to_remove = _wp_filter_build_unique_id( $tag, $function_to_remove, $priority );

	$r = isset( $GLOBALS['wp_filter'][ $tag ][ $priority ][ $function_to_remove ] );

	if ( true === $r ) {
		unset( $GLOBALS['wp_filter'][ $tag ][ $priority ][ $function_to_remove ] );
		if ( empty( $GLOBALS['wp_filter'][ $tag ][ $priority ] ) ) {
			unset( $GLOBALS['wp_filter'][ $tag ][ $priority ] );
		}
		if ( empty( $GLOBALS['wp_filter'][ $tag ] ) ) {
			$GLOBALS['wp_filter'][ $tag ] = array();
		}
		unset( $GLOBALS['merged_filters'][ $tag ] );
	}

	return $r;
}
更新版本 源码位置 使用 被使用
1.2.0 wp-includes/plugin.php:276 40 0

笔记(Notes)

例子

类别:WordPress 函数手册

本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。

评论 (0)COMMENT

登录 账号发表你的看法,还没有账号?立即免费 注册