Using WordPress ‘pre_auto_update’ PHP action

The pre_auto_update WordPress PHP action fires immediately prior to an auto-update, providing the opportunity to modify the auto-update behavior.

Usage

add_action('pre_auto_update', 'my_custom_auto_update', 10, 3);

function my_custom_auto_update($type, $item, $context) {
    // your custom code here
}

Parameters

  • $type (string) – The type of update being checked: ‘core’, ‘theme’, ‘plugin’, or ‘translation’.
  • $item (object) – The update offer.
  • $context (string) – The filesystem context (a path) against which filesystem access and status should be checked.

More information

See WordPress Developer Resources: pre_auto_update

Examples

Disable auto-updates for plugins

Disable auto-updates for all plugins:

function disable_plugin_auto_updates($type, $item, $context) {
    if ('plugin' === $type) {
        return false;
    }
}
add_action('pre_auto_update', 'disable_plugin_auto_updates', 10, 3);

Disable auto-updates for a specific plugin

Disable auto-updates for a specific plugin, in this case “example-plugin”:

function disable_specific_plugin_auto_update($type, $item, $context) {
    if ('plugin' === $type && 'example-plugin' === $item->slug) {
        return false;
    }
}
add_action('pre_auto_update', 'disable_specific_plugin_auto_update', 10, 3);

Disable auto-updates for themes

Disable auto-updates for all themes:

function disable_theme_auto_updates($type, $item, $context) {
    if ('theme' === $type) {
        return false;
    }
}
add_action('pre_auto_update', 'disable_theme_auto_updates', 10, 3);

Disable auto-updates for a specific theme

Disable auto-updates for a specific theme, in this case “example-theme”:

function disable_specific_theme_auto_update($type, $item, $context) {
    if ('theme' === $type && 'example-theme' === $item->slug) {
        return false;
    }
}
add_action('pre_auto_update', 'disable_specific_theme_auto_update', 10, 3);

Log auto-update events

Log auto-update events for debugging purposes:

function log_auto_update_events($type, $item, $context) {
    error_log("Auto-update event: Type: {$type}, Slug: {$item->slug}, Context: {$context}");
}
add_action('pre_auto_update', 'log_auto_update_events', 10, 3);