Using WordPress ‘after_core_auto_updates_settings’ PHP action

The after_core_auto_updates_settings WordPress action fires after the major core auto-update settings are configured. It contains an array of core auto-update settings.

Usage

add_action('after_core_auto_updates_settings', 'my_custom_function');
function my_custom_function($auto_update_settings) {
    // your custom code here
}

Parameters

  • $auto_update_settings (array): Array of core auto-update settings.
    • dev (bool): Whether to enable automatic updates for development versions.
    • minor (bool): Whether to enable minor automatic core updates.
    • major (bool): Whether to enable major automatic core updates.

More information

See WordPress Developer Resources: after_core_auto_updates_settings

Examples

Log auto-update settings

Log the current auto-update settings to a custom log file.

add_action('after_core_auto_updates_settings', 'log_auto_update_settings');
function log_auto_update_settings($auto_update_settings) {
    // Convert the settings array to a string
    $settings_str = print_r($auto_update_settings, true);
    // Write the settings string to a log file
    error_log($settings_str, 3, '/path/to/your/logfile.log');
}

Disable major auto-updates

Disable major auto-updates when the action is triggered.

add_action('after_core_auto_updates_settings', 'disable_major_auto_updates');
function disable_major_auto_updates($auto_update_settings) {
    // Disable major auto-updates
    $auto_update_settings['major'] = false;
}

Enable all auto-updates

Enable all types of auto-updates when the action is triggered.

add_action('after_core_auto_updates_settings', 'enable_all_auto_updates');
function enable_all_auto_updates($auto_update_settings) {
    // Enable all auto-updates
    $auto_update_settings['dev'] = true;
    $auto_update_settings['minor'] = true;
    $auto_update_settings['major'] = true;
}

Send auto-update settings via email

Send the current auto-update settings via email to the website administrator.

add_action('after_core_auto_updates_settings', 'email_auto_update_settings');
function email_auto_update_settings($auto_update_settings) {
    // Get admin email
    $admin_email = get_option('admin_email');
    // Set email subject
    $subject = 'Auto-update settings';
    // Convert the settings array to a string
    $message = print_r($auto_update_settings, true);
    // Send email to admin
    wp_mail($admin_email, $subject, $message);
}

Update auto-update settings based on the environment

Enable or disable auto-update settings based on the current environment.

add_action('after_core_auto_updates_settings', 'env_based_auto_updates');
function env_based_auto_updates($auto_update_settings) {
    // Check if the environment is production
    if (defined('WP_ENV') && WP_ENV === 'production') {
        // Disable development auto-updates
        $auto_update_settings['dev'] = false;
        // Enable minor and major auto-updates
        $auto_update_settings['minor'] = true;
        $auto_update_settings['major'] = true;
    } else {
        // Enable all auto-updates for non-production environments
        $auto_update_settings['dev'] = true;
        $auto_update_settings['minor'] = true;
        $auto_update_settings['major'] = true;
    }
}