Using WordPress ‘dismiss_core_update()’ PHP function

The dismiss_core_update() WordPress PHP function is used to dismiss core WordPress updates.

Usage

Here’s a simple way to use this function:

$core_update = get_core_updates()[0]; // Get the first core update
if( !empty($core_update) ) {
    dismiss_core_update($core_update); // Dismiss the update
}

In this case, the first available core update is retrieved and dismissed.

Parameters

  • $update (object) – The update object that you want to dismiss. This is a required parameter.

More information

See WordPress Developer Resources: dismiss_core_update

This function has been in use since WordPress version 3.7.0. No deprecation notice as of the latest version.

Examples

Dismissing a Single Core Update

This code shows how to dismiss a single core update.

$core_update = get_core_updates()[0]; // Get the first core update

if( !empty($core_update) ) {
    dismiss_core_update($core_update); // Dismiss the update
}

Here, we’re getting the first core update and dismissing it. If there’s no update, no action is performed.

Dismissing All Core Updates

This code shows how to dismiss all available core updates.

$core_updates = get_core_updates(); // Get all core updates

foreach($core_updates as $update) {
    dismiss_core_update($update); // Dismiss each update
}

In this example, all core updates are fetched and each one is dismissed individually.

Conditional Dismissal of Core Updates

Here’s how to dismiss core updates based on some conditions.

$core_updates = get_core_updates(); // Get all core updates

foreach($core_updates as $update) {
    if($update->current < '4.5') {
        dismiss_core_update($update); // Dismiss the update if the current version is less than 4.5
    }
}

In this example, only updates for versions less than 4.5 are dismissed.

Dismissing Core Updates using a Custom Function

This code shows how to use a custom function to dismiss updates.

function my_custom_dismiss_updates() {
    $core_updates = get_core_updates(); // Get all core updates

    foreach($core_updates as $update) {
        dismiss_core_update($update); // Dismiss each update
    }
}

add_action('admin_init', 'my_custom_dismiss_updates'); // Add this to the admin_init action

In this case, we’ve created a custom function to dismiss all updates, and added it to the admin_init action to run when the WordPress admin is initialized.

Dismissing Core Updates Based on User Role

This code shows how to dismiss updates based on the user’s role.

$current_user = wp_get_current_user(); // Get the current user

if(in_array('subscriber', $current_user->roles)) {
    $core_updates = get_core_updates(); // Get all core updates

    foreach($core_updates as $update) {
        dismiss_core_update($update); // Dismiss each update
    }
}

Here, we’re checking if the current user has the “subscriber” role. If they do, all core updates are dismissed.