WP_Translation_Controller::unload_textdomain( string $textdomain = 'default', string $locale = null ): bool

In this article

Unloads all translation files for a given text domain.

Parameters

$textdomainstringoptional
Text domain. Default 'default'.

Default:'default'

$localestringoptional
Locale. Defaults to all locales.

Default:null

Return

bool True on success, false otherwise.

Source

public function unload_textdomain( string $textdomain = 'default', ?string $locale = null ): bool {
	$unloaded = false;

	if ( null !== $locale ) {
		if ( isset( $this->loaded_translations[ $locale ][ $textdomain ] ) ) {
			$unloaded = true;
			foreach ( $this->loaded_translations[ $locale ][ $textdomain ] as $moe ) {
				unset( $this->loaded_files[ $moe->get_file() ][ $locale ][ $textdomain ] );
			}
		}

		unset( $this->loaded_translations[ $locale ][ $textdomain ] );

		return $unloaded;
	}

	foreach ( $this->loaded_translations as $l => $domains ) {
		if ( ! isset( $domains[ $textdomain ] ) ) {
			continue;
		}

		$unloaded = true;

		foreach ( $domains[ $textdomain ] as $moe ) {
			unset( $this->loaded_files[ $moe->get_file() ][ $l ][ $textdomain ] );
		}

		unset( $this->loaded_translations[ $l ][ $textdomain ] );
	}

	return $unloaded;
}

Changelog

VersionDescription
6.5.0Introduced.

User Contributed Notes

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