Unloads a translation file for a given text domain.
Parameters
$file
WP_Translation_File|stringrequired- Translation file instance or file name.
$textdomain
stringoptional- Text domain. Default
'default'
.Default:
'default'
$locale
stringoptional- Locale. Defaults to all locales.
Default:
null
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
Version | Description |
---|---|
6.5.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.