Invalidate the cache for .mo files.
Description
This function deletes the cache entries related to .mo files when triggered by specific actions, such as the completion of an upgrade process.
Parameters
$upgraderWP_Upgraderrequired- Unused. WP_Upgrader instance. In other contexts this might be a Theme_Upgrader, Plugin_Upgrader, Core_Upgrade, or Language_Pack_Upgrader instance.
$hook_extraarrayrequired- Array of bulk item update data.
actionstringType of action. Default'update'.typestringType of update process. Accepts'plugin','theme','translation', or'core'.bulkboolWhether the update process is a bulk update. Default true.pluginsarrayArray of the basename paths of the plugins’ main files.themesarrayThe theme slugs.translationsarrayArray of translations update data.languagestringThe locale the translation is for.typestringType of translation. Accepts'plugin','theme', or'core'.slugstringText domain the translation is for. The slug of a theme/plugin or'default'for core translations.versionstringThe version of a theme, plugin, or core.
Source
public function invalidate_mo_files_cache( $upgrader, $hook_extra ) {
if (
! isset( $hook_extra['type'] ) ||
'translation' !== $hook_extra['type'] ||
array() === $hook_extra['translations']
) {
return;
}
$translation_types = array_unique( wp_list_pluck( $hook_extra['translations'], 'type' ) );
foreach ( $translation_types as $type ) {
switch ( $type ) {
case 'plugin':
wp_cache_delete( md5( WP_LANG_DIR . '/plugins/' ), 'translation_files' );
break;
case 'theme':
wp_cache_delete( md5( WP_LANG_DIR . '/themes/' ), 'translation_files' );
break;
default:
wp_cache_delete( md5( WP_LANG_DIR . '/' ), 'translation_files' );
break;
}
}
}
Changelog
| Version | Description |
|---|---|
| 6.5.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.