Skip to content

Instantly share code, notes, and snippets.

@peterwilsoncc
Created June 28, 2021 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterwilsoncc/689be020e5aa6561b0189cba59090c26 to your computer and use it in GitHub Desktop.
Save peterwilsoncc/689be020e5aa6561b0189cba59090c26 to your computer and use it in GitHub Desktop.
diff --git a/src/wp-admin/includes/update-core.php b/src/wp-admin/includes/update-core.php
index 731690fa9a..484eb8552f 100644
--- a/src/wp-admin/includes/update-core.php
+++ b/src/wp-admin/includes/update-core.php
@@ -1671,18 +1671,33 @@ function _upgrade_440_force_deactivate_incompatible_plugins() {
* @since 5.8.0
*/
function _upgrade_580_force_deactivate_incompatible_plugins() {
- if ( defined( 'GUTENBERG_VERSION' ) && version_compare( GUTENBERG_VERSION, '10.7', '<=' ) ) {
- $deactivated_plugins = get_option( 'wp_deactivated_plugins', array() );
- $deactivated_plugins['gutenberg'] = array(
- 'plugin_name' => 'Gutenberg',
- 'version_deactivated' => GUTENBERG_VERSION,
- 'version_compatible' => '10.8',
- );
- if ( is_plugin_active_for_network( 'gutenberg/gutenberg.php' ) ) {
- update_site_option( 'wp_deactivated_plugins', $deactivated_plugins );
- } else {
- update_option( 'wp_deactivated_plugins', $deactivated_plugins );
- }
- deactivate_plugins( array( 'gutenberg/gutenberg.php' ), true );
+ if ( ! file_exists( WP_PLUGIN_DIR . '/gutenberg/gutenberg.php' ) ) {
+ // Gutenberg is not installed.
+ return;
+ }
+ $gutenberg_data = get_plugin_data( WP_PLUGIN_DIR . '/gutenberg/gutenberg.php' );
+ $gutenberg_version = ! empty( $gutenberg_data['Version'] ) ? $gutenberg_data['Version'] : false;
+
+ if ( ! $gutenberg_version ) {
+ // This may not be Gutenberg.
+ return;
+ }
+
+ if ( ! version_compare( $gutenberg_version, '10.7', '<=' ) ) {
+ // This version of Gutenberg is compatible with WP 5.8.
+ return;
+ }
+
+ $deactivated_plugins = get_option( 'wp_deactivated_plugins', array() );
+ $deactivated_plugins['gutenberg'] = array(
+ 'plugin_name' => 'Gutenberg',
+ 'version_deactivated' => $gutenberg_version,
+ 'version_compatible' => '10.8',
+ );
+ if ( is_plugin_active_for_network( 'gutenberg/gutenberg.php' ) ) {
+ update_site_option( 'wp_deactivated_plugins', $deactivated_plugins );
+ } else {
+ update_option( 'wp_deactivated_plugins', $deactivated_plugins );
}
+ deactivate_plugins( array( 'gutenberg/gutenberg.php' ), true );
}
diff --git a/src/wp-admin/includes/upgrade.php b/src/wp-admin/includes/upgrade.php
index 475608efa7..0e44afe4d3 100644
--- a/src/wp-admin/includes/upgrade.php
+++ b/src/wp-admin/includes/upgrade.php
@@ -674,6 +674,44 @@ if ( ! function_exists( 'wp_upgrade' ) ) :
}
endif;
+
+function _upgrade_580_force_deactivate_incompatible_plugins() {
+ trigger_error( '1' );
+ if ( ! file_exists( WP_PLUGIN_DIR . '/gutenberg/gutenberg.php' ) ) {
+ // Gutenberg is not installed.
+ return;
+ }
+ trigger_error( '2' );
+ $gutenberg_data = get_plugin_data( WP_PLUGIN_DIR . '/gutenberg/gutenberg.php' );
+ $gutenberg_version = ! empty( $gutenberg_data['Version'] ) ? $gutenberg_data['Version'] : false;
+
+ if ( ! $gutenberg_version ) {
+ // This may not be Gutenberg.
+ return;
+ }
+
+ trigger_error( "3: $gutenberg_version" );
+ if ( ! version_compare( $gutenberg_version, '10.7', '<=' ) ) {
+ // This version of Gutenberg is compatible with WP 5.8.
+ return;
+ }
+
+ trigger_error( '4' );
+ $deactivated_plugins = get_option( 'wp_deactivated_plugins', array() );
+ $deactivated_plugins['gutenberg'] = array(
+ 'plugin_name' => 'Gutenberg',
+ 'version_deactivated' => $gutenberg_version,
+ 'version_compatible' => '10.8',
+ );
+ if ( is_plugin_active_for_network( 'gutenberg/gutenberg.php' ) ) {
+ update_site_option( 'wp_deactivated_plugins', $deactivated_plugins );
+ } else {
+ update_option( 'wp_deactivated_plugins', $deactivated_plugins );
+ }
+ deactivate_plugins( array( 'gutenberg/gutenberg.php' ), true );
+}
+
+
/**
* Functions to be called in installation and upgrade scripts.
*
@@ -687,6 +725,9 @@ endif;
* @global int $wp_db_version The new database version.
*/
function upgrade_all() {
+
+ _upgrade_580_force_deactivate_incompatible_plugins();
+
global $wp_current_db_version, $wp_db_version;
$wp_current_db_version = __get_option( 'db_version' );
diff --git a/src/wp-includes/version.php b/src/wp-includes/version.php
index 24d180bc05..22844b3fcb 100644
--- a/src/wp-includes/version.php
+++ b/src/wp-includes/version.php
@@ -20,7 +20,7 @@ $wp_version = '5.8-beta4-51243-src';
*
* @global int $wp_db_version
*/
-$wp_db_version = 49752;
+$wp_db_version = 49764;
/**
* Holds the TinyMCE version.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment