Upgrade/Install: Deactivate the Gutenberg plugin if its version is 11.8 or lower.

Avoid a fatal error due to `WP_Theme_JSON_Schema` and potentially other classes and/or functions redeclarations when updating to WordPress 5.9 with an incompatible version of the Gutenberg plugin.

This commit uses the same strategy from 5.8. Moves the plugin deactivation code (introduced in [51266]) to a private function for reuse in 5.8, 5.9, and future major releases.

Follow-up to [51180], [51266].

Props hellofromTonya, johnbillion, jorbin.
See #54405.
Built from https://develop.svn.wordpress.org/trunk@52165


git-svn-id: http://core.svn.wordpress.org/trunk@51757 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
hellofromTonya 2021-11-15 19:59:03 +00:00
parent 9043992e3b
commit 1f608d5d5c
2 changed files with 44 additions and 16 deletions

View File

@ -1401,6 +1401,9 @@ function update_core( $from, $to ) {
// Deactivate the Gutenberg plugin if its version is 10.7 or lower.
_upgrade_580_force_deactivate_incompatible_plugins();
// Deactivate the Gutenberg plugin if its version is 11.8 or lower.
_upgrade_590_force_deactivate_incompatible_plugins();
// Upgrade DB with separate request.
/** This filter is documented in wp-admin/includes/update-core.php */
apply_filters( 'update_feedback', __( 'Upgrading database…' ) );
@ -1685,25 +1688,50 @@ function _upgrade_440_force_deactivate_incompatible_plugins() {
}
/**
* @access private
* @ignore
* @since 5.8.0
*/
function _upgrade_580_force_deactivate_incompatible_plugins() {
if ( defined( 'GUTENBERG_VERSION' ) && version_compare( GUTENBERG_VERSION, '10.7', '<=' ) ) {
$deactivated_gutenberg['gutenberg'] = array(
'plugin_name' => 'Gutenberg',
'version_deactivated' => GUTENBERG_VERSION,
'version_compatible' => '10.8',
);
if ( is_plugin_active_for_network( 'gutenberg/gutenberg.php' ) ) {
$deactivated_plugins = get_site_option( 'wp_force_deactivated_plugins', array() );
$deactivated_plugins = array_merge( $deactivated_plugins, $deactivated_gutenberg );
update_site_option( 'wp_force_deactivated_plugins', $deactivated_plugins );
} else {
$deactivated_plugins = get_option( 'wp_force_deactivated_plugins', array() );
$deactivated_plugins = array_merge( $deactivated_plugins, $deactivated_gutenberg );
update_option( 'wp_force_deactivated_plugins', $deactivated_plugins );
}
deactivate_plugins( array( 'gutenberg/gutenberg.php' ), true );
_deactivate_gutenberg_when_incompatible_with_wp( '10.8' );
}
}
/**
* @access private
* @ignore
* @since 5.9.0
*/
function _upgrade_590_force_deactivate_incompatible_plugins() {
if ( defined( 'GUTENBERG_VERSION' ) && version_compare( GUTENBERG_VERSION, '11.8', '<=' ) ) {
_deactivate_gutenberg_when_incompatible_with_wp( '11.9' );
}
}
/**
* Deactivates the Gutenberg plugin when its version is incompatible.
*
* @access private
* @ignore
* @since 5.9.0
*
* @param string $compatible_version The version of Gutenberg plugin that is compatible.
*/
function _deactivate_gutenberg_when_incompatible_with_wp( $compatible_version ) {
$deactivated_gutenberg['gutenberg'] = array(
'plugin_name' => 'Gutenberg',
'version_deactivated' => GUTENBERG_VERSION,
'version_compatible' => $compatible_version,
);
if ( is_plugin_active_for_network( 'gutenberg/gutenberg.php' ) ) {
$deactivated_plugins = get_site_option( 'wp_force_deactivated_plugins', array() );
$deactivated_plugins = array_merge( $deactivated_plugins, $deactivated_gutenberg );
update_site_option( 'wp_force_deactivated_plugins', $deactivated_plugins );
} else {
$deactivated_plugins = get_option( 'wp_force_deactivated_plugins', array() );
$deactivated_plugins = array_merge( $deactivated_plugins, $deactivated_gutenberg );
update_option( 'wp_force_deactivated_plugins', $deactivated_plugins );
}
deactivate_plugins( array( 'gutenberg/gutenberg.php' ), true );
}

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.9-alpha-52164';
$wp_version = '5.9-alpha-52165';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.