: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
if ( ! mkdir( $site_dir, 0777 ) ) {
if ( file_exists( ABSPATH . 'wp-layout.css' ) ) {
if ( ! make_site_theme_from_oldschool( $theme_name, $template ) ) {
// TODO: rm -rf the site theme directory.
if ( ! make_site_theme_from_default( $theme_name, $template ) ) {
// TODO: rm -rf the site theme directory.
// Make the new site theme active.
$current_template = __get_option( 'template' );
if ( WP_DEFAULT_THEME == $current_template ) {
update_option( 'template', $template );
update_option( 'stylesheet', $template );
* Translate user level to user role name.
* @param int $level User level.
* @return string User role name.
function translate_level_to_role( $level ) {
* Checks the version of the installed MySQL binary.
* @global wpdb $wpdb WordPress database abstraction object.
function wp_check_mysql_version() {
$result = $wpdb->check_database_version();
if ( is_wp_error( $result ) ) {
* Disables the Automattic widgets plugin, which was merged into core.
function maybe_disable_automattic_widgets() {
$plugins = __get_option( 'active_plugins' );
foreach ( (array) $plugins as $plugin ) {
if ( 'widgets.php' === basename( $plugin ) ) {
array_splice( $plugins, array_search( $plugin, $plugins, true ), 1 );
update_option( 'active_plugins', $plugins );
* Disables the Link Manager on upgrade if, at the time of upgrade, no links exist in the DB.
* @global int $wp_current_db_version The old (current) database version.
* @global wpdb $wpdb WordPress database abstraction object.
function maybe_disable_link_manager() {
global $wp_current_db_version, $wpdb;
if ( $wp_current_db_version >= 22006 && get_option( 'link_manager_enabled' ) && ! $wpdb->get_var( "SELECT link_id FROM $wpdb->links LIMIT 1" ) ) {
update_option( 'link_manager_enabled', 0 );
* Runs before the schema is upgraded.
* @global int $wp_current_db_version The old (current) database version.
* @global wpdb $wpdb WordPress database abstraction object.
function pre_schema_upgrade() {
global $wp_current_db_version, $wpdb;
// Upgrade versions prior to 2.9.
if ( $wp_current_db_version < 11557 ) {
// Delete duplicate options. Keep the option with the highest option_id.
$wpdb->query( "DELETE o1 FROM $wpdb->options AS o1 JOIN $wpdb->options AS o2 USING (`option_name`) WHERE o2.option_id > o1.option_id" );
// Drop the old primary key and add the new.
$wpdb->query( "ALTER TABLE $wpdb->options DROP PRIMARY KEY, ADD PRIMARY KEY(option_id)" );
// Drop the old option_name index. dbDelta() doesn't do the drop.
$wpdb->query( "ALTER TABLE $wpdb->options DROP INDEX option_name" );
// Multisite schema upgrades.
if ( $wp_current_db_version < 25448 && is_multisite() && wp_should_upgrade_global_tables() ) {
// Upgrade versions prior to 3.7.
if ( $wp_current_db_version < 25179 ) {
// New primary key for signups.
$wpdb->query( "ALTER TABLE $wpdb->signups ADD signup_id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST" );
$wpdb->query( "ALTER TABLE $wpdb->signups DROP INDEX domain" );
if ( $wp_current_db_version < 25448 ) {
// Convert archived from enum to tinyint.
$wpdb->query( "ALTER TABLE $wpdb->blogs CHANGE COLUMN archived archived varchar(1) NOT NULL default '0'" );
$wpdb->query( "ALTER TABLE $wpdb->blogs CHANGE COLUMN archived archived tinyint(2) NOT NULL default 0" );
// Upgrade versions prior to 4.2.
if ( $wp_current_db_version < 31351 ) {
if ( ! is_multisite() && wp_should_upgrade_global_tables() ) {
$wpdb->query( "ALTER TABLE $wpdb->usermeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
$wpdb->query( "ALTER TABLE $wpdb->terms DROP INDEX slug, ADD INDEX slug(slug(191))" );
$wpdb->query( "ALTER TABLE $wpdb->terms DROP INDEX name, ADD INDEX name(name(191))" );
$wpdb->query( "ALTER TABLE $wpdb->commentmeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
$wpdb->query( "ALTER TABLE $wpdb->postmeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
$wpdb->query( "ALTER TABLE $wpdb->posts DROP INDEX post_name, ADD INDEX post_name(post_name(191))" );
// Upgrade versions prior to 4.4.
if ( $wp_current_db_version < 34978 ) {
// If compatible termmeta table is found, use it, but enforce a proper index and update collation.
if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->termmeta}'" ) && $wpdb->get_results( "SHOW INDEX FROM {$wpdb->termmeta} WHERE Column_name = 'meta_key'" ) ) {
$wpdb->query( "ALTER TABLE $wpdb->termmeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
maybe_convert_table_to_utf8mb4( $wpdb->termmeta );
* Determine if global tables should be upgraded.
* 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 bool Whether to run the upgrade routines on global tables.
function wp_should_upgrade_global_tables() {
// Return false early if explicitly not upgrading.
if ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) {
// Assume global tables should be upgraded.
// Set to false if not on main network (does not matter if not multi-network).
if ( ! is_main_network() ) {
// Set to false if not on main site of current network (does not matter if not multi-site).
if ( ! is_main_site() ) {
* Filters if upgrade routines should be run on global tables.
* @param bool $should_upgrade Whether to run the upgrade routines on global tables.
return apply_filters( 'wp_should_upgrade_global_tables', $should_upgrade );