unload_textdomain

函数
unload_textdomain ( $domain, $reloadable = false )
参数
  • (string) $domain Text domain. Unique identifier for retrieving translated strings.
    Required:
  • (bool) $reloadable Whether the text domain can be loaded just-in-time again.
    Required:
    Default: false
返回值
  • (bool) Whether textdomain was unloaded.
定义位置
相关方法
load_textdomainload_theme_textdomainload_script_textdomainload_plugin_textdomainload_default_textdomain
引入
3.0.0
弃用
-

unload_textdomain: 这个函数卸载一个由load_plugin_textdomain()或load_theme_textdomain加载的翻译文件。它需要一个参数,$domain,它是翻译文件的唯一标识符。

为一个文本域卸载翻译。

function unload_textdomain( $domain, $reloadable = false ) {
	global $l10n, $l10n_unloaded;

	$l10n_unloaded = (array) $l10n_unloaded;

	/**
	 * Filters whether to override the text domain unloading.
	 *
	 * @since 3.0.0
	 * @since 6.1.0 Added the `$reloadable` parameter.
	 *
	 * @param bool   $override   Whether to override the text domain unloading. Default false.
	 * @param string $domain     Text domain. Unique identifier for retrieving translated strings.
	 * @param bool   $reloadable Whether the text domain can be loaded just-in-time again.
	 */
	$plugin_override = apply_filters( 'override_unload_textdomain', false, $domain, $reloadable );

	if ( $plugin_override ) {
		if ( ! $reloadable ) {
			$l10n_unloaded[ $domain ] = true;
		}

		return true;
	}

	/**
	 * Fires before the text domain is unloaded.
	 *
	 * @since 3.0.0
	 * @since 6.1.0 Added the `$reloadable` parameter.
	 *
	 * @param string $domain     Text domain. Unique identifier for retrieving translated strings.
	 * @param bool   $reloadable Whether the text domain can be loaded just-in-time again.
	 */
	do_action( 'unload_textdomain', $domain, $reloadable );

	if ( isset( $l10n[ $domain ] ) ) {
		unset( $l10n[ $domain ] );

		if ( ! $reloadable ) {
			$l10n_unloaded[ $domain ] = true;
		}

		return true;
	}

	return false;
}

常见问题

FAQs
查看更多 >