Using WordPress ‘do_mu_upgrade’ PHP filter

The do_mu_upgrade WordPress PHP filter controls whether to attempt the multisite database upgrade routine or not.

Usage

add_filter('do_mu_upgrade', 'your_custom_function');

function your_custom_function($do_mu_upgrade) {
  // your custom code here
  return $do_mu_upgrade;
}

Parameters

  • $do_mu_upgrade (bool) – Whether to perform the Multisite upgrade routine. Default is true.

More information

See WordPress Developer Resources: do_mu_upgrade

Examples

Disable multisite upgrade routine

Disable the multisite database upgrade routine completely.

add_filter('do_mu_upgrade', '__return_false');

Enable multisite upgrade routine for networks with more than 100 sites

Allow the multisite database upgrade routine to run only on networks with more than 100 sites.

add_filter('do_mu_upgrade', 'allow_upgrade_for_large_networks');

function allow_upgrade_for_large_networks($do_mu_upgrade) {
  $network_sites_count = get_blog_count();

  if ($network_sites_count > 100) {
    return true;
  }

  return $do_mu_upgrade;
}

Run multisite upgrade routine only during specific time periods

Only run the multisite database upgrade routine during specific hours of the day, like outside of peak traffic hours.

add_filter('do_mu_upgrade', 'upgrade_during_off_peak_hours');

function upgrade_during_off_peak_hours($do_mu_upgrade) {
  $current_hour = date('G');

  if ($current_hour >= 0 && $current_hour <= 5) {
    return true;
  }

  return $do_mu_upgrade;
}

Run multisite upgrade routine only if a specific user is logged in

Allow the multisite database upgrade routine to run only if a specific user is logged in.

add_filter('do_mu_upgrade', 'upgrade_when_user_is_logged_in');

function upgrade_when_user_is_logged_in($do_mu_upgrade) {
  $allowed_user = 'admin_username';

  if (is_user_logged_in() && wp_get_current_user()->user_login === $allowed_user) {
    return true;
  }

  return $do_mu_upgrade;
}

Customize multisite upgrade routine based on custom site option

Run the multisite database upgrade routine only if a custom site option is set to ‘true’.

add_filter('do_mu_upgrade', 'upgrade_based_on_custom_option');

function upgrade_based_on_custom_option($do_mu_upgrade) {
  $custom_option = get_option('custom_upgrade_option', 'false');

  if ($custom_option === 'true') {
    return true;
  }

  return $do_mu_upgrade;
}