Using WordPress ‘async_update_translation’ PHP filter

The async_update_translation WordPress PHP filter allows you to control whether to update translations for core, a plugin, or a theme asynchronously.

Usage

add_filter('async_update_translation', 'your_custom_function', 10, 2);

function your_custom_function($update, $language_update) {
    // your custom code here
    return $update;
}

Parameters

  • $update (bool): Whether to update the translation asynchronously.
  • $language_update (object): The update offer object, containing the details of the translation update.

More Information

See WordPress Developer Resources: async_update_translation

Examples

Prevent Asynchronous Translation Updates

Prevent all asynchronous updates for translations by returning false.

add_filter('async_update_translation', 'disable_async_translation_updates', 10, 2);

function disable_async_translation_updates($update, $language_update) {
    return false;
}

Only Allow Core Asynchronous Translation Updates

Allow asynchronous translation updates only for WordPress core.

add_filter('async_update_translation', 'allow_core_async_translation_updates', 10, 2);

function allow_core_async_translation_updates($update, $language_update) {
    if ($language_update->type === 'core') {
        return true;
    }
    return false;
}

Enable Asynchronous Translation Updates for Specific Plugin

Enable asynchronous translation updates for a specific plugin, identified by its slug.

add_filter('async_update_translation', 'enable_specific_plugin_async_translation_updates', 10, 2);

function enable_specific_plugin_async_translation_updates($update, $language_update) {
    if ($language_update->type === 'plugin' && $language_update->slug === 'your-plugin-slug') {
        return true;
    }
    return $update;
}

Enable Asynchronous Translation Updates for Specific Theme

Enable asynchronous translation updates for a specific theme, identified by its slug.

add_filter('async_update_translation', 'enable_specific_theme_async_translation_updates', 10, 2);

function enable_specific_theme_async_translation_updates($update, $language_update) {
    if ($language_update->type === 'theme' && $language_update->slug === 'your-theme-slug') {
        return true;
    }
    return $update;
}

Enable Asynchronous Translation Updates Based on Language

Enable asynchronous translation updates only for a specific language.

add_filter('async_update_translation', 'enable_specific_language_async_translation_updates', 10, 2);

function enable_specific_language_async_translation_updates($update, $language_update) {
    if ($language_update->language === 'en_US') {
        return true;
    }
    return $update;
}