WP_Translation_Controller::unload_file( WP_Translation_File|string $file, string $textdomain = ‘default’, string $locale = null ): bool

In this article

Unloads a translation file for a given text domain.

Parameters

$fileWP_Translation_File|stringrequired
Translation file instance or file name.
$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_file( $file, string $textdomain = 'default', ?string $locale = null ): bool {
	if ( is_string( $file ) ) {
		$file = realpath( $file );
	}

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

		return true;
	}

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

		foreach ( $domains[ $textdomain ] as $i => $moe ) {
			if ( $file === $moe || $file === $moe->get_file() ) {
				unset( $this->loaded_translations[ $l ][ $textdomain ][ $i ] );
				unset( $this->loaded_files[ $moe->get_file() ][ $l ][ $textdomain ] );
				return true;
			}
		}
	}

	return false;
}

Changelog

VersionDescription
6.5.0Introduced.

User Contributed Notes

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