
如何使用代码和插件创建WordPress活动事件
wp_should_upgrade_global_tables ( No parameters )
确定全局表是否应该被升级。
这个函数执行一系列的检查,以确保环境允许全局WordPress数据库表的安全升级。它是必要的,因为全局表在大型安装中通常会增长到数百万行,而控制其升级程序的能力对大型网络的运行至关重要。
在未来的迭代中,这个函数可能会使用`wp_is_large_network()`来更智能地防止全局表的升级。在那之前,我们要确保WordPress是在主网络的主站点上,以避免在多站点或多网络环境中多次运行查询。
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 ); }