WP_Translation_Controller::unload_file
Unloads a translation file for a given text domain.
Method of the class: WP_Translation_Controller{}
No Hooks.
Returns
true|false. True on success, false otherwise.
Usage
$WP_Translation_Controller = new WP_Translation_Controller(); $WP_Translation_Controller->unload_file( $file, $textdomain, ?string $locale ): bool;
- $file(WP_Translation_File|string) (required)
- Translation file instance or file name.
- $textdomain(string)
- Text domain.
Default: 'default' - ?string $locale
- .
Default: null
Changelog
| Since 6.5.0 | Introduced. |
WP_Translation_Controller::unload_file() WP Translation Controller::unload file code WP 6.8.3
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;
}