Title: wp_should_upgrade_global_tables
Published: August 18, 2015
Last modified: August 20, 2026

---

# wp_should_upgrade_global_tables(): bool

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/wp_should_upgrade_global_tables/?output_format=md#description)
 * [Return](https://developer.wordpress.org/reference/functions/wp_should_upgrade_global_tables/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_should_upgrade_global_tables/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/wp_should_upgrade_global_tables/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/wp_should_upgrade_global_tables/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_should_upgrade_global_tables/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_should_upgrade_global_tables/?output_format=md#wp--skip-link--target)

Determine if global tables should be upgraded.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/wp_should_upgrade_global_tables/?output_format=md#description)󠁿

This function performs a series of checks to ensure the environment allows for the
safe upgrading of global WordPress database tables. It is necessary because global
tables will commonly grow to millions of rows on large installations, and the ability
to control their upgrade routines can be critical to the operation of large networks.

In a future iteration, this function may use `wp_is_large_network()` to more- intelligently
prevent global table upgrades. Until then, we make sure WordPress is on the main
site of the main network, to avoid running queries more than once in multi-site 
or multi-network environments.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_should_upgrade_global_tables/?output_format=md#return)󠁿

 bool Whether to run the upgrade routines on global tables.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_should_upgrade_global_tables/?output_format=md#source)󠁿

    ```php
    function wp_should_upgrade_global_tables() {

    	// Return false early if explicitly not upgrading.
    	if ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) {
    		return false;
    	}

    	// Assume global tables should be upgraded.
    	$should_upgrade = true;

    	// Set to false if not on main network (does not matter if not multi-network).
    	if ( ! is_main_network() ) {
    		$should_upgrade = false;
    	}

    	// Set to false if not on main site of current network (does not matter if not multi-site).
    	if ( ! is_main_site() ) {
    		$should_upgrade = false;
    	}

    	/**
    	 * Filters if upgrade routines should be run on global tables.
    	 *
    	 * @since 4.3.0
    	 *
    	 * @param bool $should_upgrade Whether to run the upgrade routines on global tables.
    	 */
    	return apply_filters( 'wp_should_upgrade_global_tables', $should_upgrade );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/upgrade.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-admin/includes/upgrade.php#L3816)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-admin/includes/upgrade.php#L3816-L3844)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/wp_should_upgrade_global_tables/?output_format=md#hooks)󠁿

 [apply_filters( ‘wp_should_upgrade_global_tables’, bool $should_upgrade )](https://developer.wordpress.org/reference/hooks/wp_should_upgrade_global_tables/)

Filters if upgrade routines should be run on global tables.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_should_upgrade_global_tables/?output_format=md#related)󠁿

| Uses | Description | 
| [is_main_network()](https://developer.wordpress.org/reference/functions/is_main_network/)`wp-includes/functions.php` |

Determines whether a network is the main network of the Multisite installation.

  | 
| [is_main_site()](https://developer.wordpress.org/reference/functions/is_main_site/)`wp-includes/functions.php` |

Determines whether a site is the main site of the current network.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/wp_should_upgrade_global_tables/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_should_upgrade_global_tables/?output_format=md#)

| Used by | Description | 
| [pre_schema_upgrade()](https://developer.wordpress.org/reference/functions/pre_schema_upgrade/)`wp-admin/includes/upgrade.php` |

Runs before the schema is upgraded.

  | 
| [upgrade_network()](https://developer.wordpress.org/reference/functions/upgrade_network/)`wp-admin/includes/upgrade.php` |

Executes network-level upgrade routines.

  | 
| [dbDelta()](https://developer.wordpress.org/reference/functions/dbdelta/)`wp-admin/includes/upgrade.php` |

Modifies the database based on specified SQL statements.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_should_upgrade_global_tables/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_should_upgrade_global_tables%2F)
before being able to contribute a note or feedback.