The after_db_upgrade WordPress action fires on the next page load after a successful database upgrade.
Usage
add_action('after_db_upgrade', 'your_custom_function');
function your_custom_function() {
// your custom code here
}
Parameters
- None
More information
See WordPress Developer Resources: after_db_upgrade
Examples
Display a message after a successful database upgrade
Display a message to the admin after the database has been successfully upgraded.
add_action('after_db_upgrade', 'display_upgrade_message');
function display_upgrade_message() {
// Display a message after a successful database upgrade
echo '<div class="notice notice-success is-dismissible"><p>Database upgrade was successful!</p></div>';
}
Log database upgrade completion
Log the timestamp of the database upgrade completion to a file.
add_action('after_db_upgrade', 'log_db_upgrade');
function log_db_upgrade() {
// Log the time of the successful database upgrade
$log_file = fopen('db_upgrade_log.txt', 'a');
fwrite($log_file, "Database upgrade completed on: " . date('Y-m-d H:i:s') . "\n");
fclose($log_file);
}
Send an email notification after a successful database upgrade
Notify the site administrator via email after the database has been successfully upgraded.
add_action('after_db_upgrade', 'send_upgrade_email');
function send_upgrade_email() {
// Send email notification after a successful database upgrade
$to = get_option('admin_email');
$subject = 'Database upgrade completed';
$message = 'Your WordPress database has been successfully upgraded.';
wp_mail($to, $subject, $message);
}
Perform additional cleanup after a database upgrade
Run a custom cleanup function after a successful database upgrade.
add_action('after_db_upgrade', 'run_custom_cleanup');
function run_custom_cleanup() {
// Custom cleanup code here
}
Update a custom option after a database upgrade
Update a custom option value in the WordPress database after a successful database upgrade.
add_action('after_db_upgrade', 'update_custom_option');
function update_custom_option() {
// Update the custom option value
update_option('my_custom_option', 'updated_after_upgrade');
}