unload_textdomain( string $domain )

Unload translations for a text domain.


Parameters Parameters

$domain

(string) (Required) Text domain. Unique identifier for retrieving translated strings.


Top ↑

Return Return

(bool) Whether textdomain was unloaded.


Top ↑

Source Source

File: wp-includes/l10n.php

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

	$l10n_unloaded = (array) $l10n_unloaded;

	/**
	 * Filters whether to override the text domain unloading.
	 *
	 * @since 3.0.0
	 *
	 * @param bool   $override Whether to override the text domain unloading. Default false.
	 * @param string $domain   Text domain. Unique identifier for retrieving translated strings.
	 */
	$plugin_override = apply_filters( 'override_unload_textdomain', false, $domain );

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

		return true;
	}

	/**
	 * Fires before the text domain is unloaded.
	 *
	 * @since 3.0.0
	 *
	 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
	 */
	do_action( 'unload_textdomain', $domain );

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

		$l10n_unloaded[ $domain ] = true;

		return true;
	}

	return false;
}


Top ↑

Changelog Changelog

Changelog
Version Description
3.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Codex

    In case you need to prevent a text domain from unloading, the override_unload_textdomain filter is called before attempting to unload the text domain.

    add_filter( 'override_unload_textdomain', 'myplugin_override_unload_textdomain' );
    function myplugin_override_unload_textdomain( $override, $domain ) {
    	if ( $domain === 'my-domain' ) {
    		// Prevents WordPress from unloading this text domain
    		$override = true;
    	}
    	return $override;
    }
    

    Immediately before unloading a text domain, the unload_textdomain action is called to notify WordPress that the text domain is being unloaded.

    add_action( 'unload_textdomain', 'myplugin_unload_textdomain' );
    function myplugin_unload_textdomain( $domain ) {
    	// add code here to handle the unloading the text domain
    }
    

You must log in before being able to contribute a note or feedback.