WordPress.org

Make WordPress Core

Changeset 51266


Ignore:
Timestamp:
06/30/2021 12:20:52 AM (3 months ago)
Author:
peterwilsoncc
Message:

Upgrade/Install: Notify users of deactivated plugins during upgrade.

This adds a one-off notice to the dashboard in the event WordPress has automatically deactivated a plugin due to incompatibility with the new version of WordPress.

Introduces the new private function deactivated_plugins_notice() to display the notice in the dashboard. Introduces the new auto-loaded option wp_force_deactivated_plugins to store a list of automatically deactivated plugins; the option is used on both a site and network level.

Follow up to [51180].

Props desrosj, jorbin, azaozz, SergeyBiryukov, peterwilsoncc.
See #53432.

Location:
trunk/src/wp-admin/includes
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/admin-filters.php

    r48412 r51266  
    115115
    116116add_action( 'admin_notices', 'update_nag', 3 );
     117add_action( 'admin_notices', 'deactivated_plugins_notice', 5 );
    117118add_action( 'admin_notices', 'paused_plugins_notice', 5 );
    118119add_action( 'admin_notices', 'paused_themes_notice', 5 );
  • trunk/src/wp-admin/includes/plugin.php

    r51092 r51266  
    24742474    );
    24752475}
     2476
     2477/**
     2478 * Renders an admin notice when a plugin was deactivated during an update.
     2479 *
     2480 * Displays an admin notice in case a plugin has been deactivated during an
     2481 * upgrade due to incompatibility with the current version of WordPress.
     2482 *
     2483 * @since 5.8.0
     2484 * @access private
     2485 *
     2486 * @global string $pagenow
     2487 * @global string $wp_version
     2488 */
     2489function deactivated_plugins_notice() {
     2490    if ( 'plugins.php' === $GLOBALS['pagenow'] ) {
     2491        return;
     2492    }
     2493
     2494    if ( ! current_user_can( 'activate_plugins' ) ) {
     2495        return;
     2496    }
     2497
     2498    $blog_deactivated_plugins = get_option( 'wp_force_deactivated_plugins' );
     2499    $site_deactivated_plugins = array();
     2500
     2501    if ( false === $blog_deactivated_plugins ) {
     2502        // Option not in database, add an empty array to avoid extra DB queries on subsequent loads.
     2503        update_option( 'wp_force_deactivated_plugins', array() );
     2504    }
     2505
     2506    if ( is_multisite() ) {
     2507        $site_deactivated_plugins = get_site_option( 'wp_force_deactivated_plugins' );
     2508        if ( false === $site_deactivated_plugins ) {
     2509            // Option not in database, add an empty array to avoid extra DB queries on subsequent loads.
     2510            update_site_option( 'wp_force_deactivated_plugins', array() );
     2511        }
     2512    }
     2513
     2514    if ( empty( $blog_deactivated_plugins ) && empty( $site_deactivated_plugins ) ) {
     2515        // No deactivated plugins.
     2516        return;
     2517    }
     2518
     2519    $deactivated_plugins = array_merge( $blog_deactivated_plugins, $site_deactivated_plugins );
     2520
     2521    foreach ( $deactivated_plugins as $plugin ) {
     2522        if ( ! empty( $plugin['version_compatible'] ) && ! empty( $plugin['version_deactivated'] ) ) {
     2523            $explanation = sprintf(
     2524                /* translators: 1: Name of deactivated plugin, 2: Plugin version deactivated, 3: Current WP version, 4: Compatible plugin version */
     2525                __( '%1$s %2$s was deactivated due to incompatibility with WordPress %3$s, please upgrade to %1$s %4$s or later.' ),
     2526                $plugin['plugin_name'],
     2527                $plugin['version_deactivated'],
     2528                $GLOBALS['wp_version'],
     2529                $plugin['version_compatible']
     2530            );
     2531        } else {
     2532            $explanation = sprintf(
     2533                /* translators: 1: Name of deactivated plugin, 2: Plugin version deactivated, 3: Current WP version */
     2534                __( '%1$s %2$s was deactivated due to incompatibility with WordPress %3$s.' ),
     2535                $plugin['plugin_name'],
     2536                ! empty( $plugin['version_deactivated'] ) ? $plugin['version_deactivated'] : '',
     2537                $GLOBALS['wp_version'],
     2538                $plugin['version_compatible']
     2539            );
     2540        }
     2541
     2542        printf(
     2543            '<div class="notice notice-warning"><p><strong>%s</strong><br>%s</p><p><a href="%s">%s</a></p></div>',
     2544            sprintf(
     2545                /* translators: %s: Name of deactivated plugin */
     2546                __( '%s plugin deactivated during WordPress upgrade.' ),
     2547                $plugin['plugin_name']
     2548            ),
     2549            $explanation,
     2550            esc_url( admin_url( 'plugins.php?plugin_status=inactive' ) ),
     2551            __( 'Go to the Plugins screen' )
     2552        );
     2553    }
     2554
     2555    // Empty the options.
     2556    update_option( 'wp_force_deactivated_plugins', array() );
     2557    if ( is_multisite() ) {
     2558        update_site_option( 'wp_force_deactivated_plugins', array() );
     2559    }
     2560}
  • trunk/src/wp-admin/includes/schema.php

    r50810 r51266  
    543543        // See https://core.trac.wordpress.org/ticket/51742.
    544544        'auto_update_core_major'          => 'enabled',
     545
     546        // 5.8.0
     547        'wp_force_deactivated_plugins'    => array(),
    545548    );
    546549
  • trunk/src/wp-admin/includes/update-core.php

    r51180 r51266  
    16731673function _upgrade_580_force_deactivate_incompatible_plugins() {
    16741674    if ( defined( 'GUTENBERG_VERSION' ) && version_compare( GUTENBERG_VERSION, '10.7', '<=' ) ) {
     1675        $deactivated_gutenberg['gutenberg'] = array(
     1676            'plugin_name'         => 'Gutenberg',
     1677            'version_deactivated' => GUTENBERG_VERSION,
     1678            'version_compatible'  => '10.8',
     1679        );
     1680        if ( is_plugin_active_for_network( 'gutenberg/gutenberg.php' ) ) {
     1681            $deactivated_plugins = get_site_option( 'wp_force_deactivated_plugins', array() );
     1682            $deactivated_plugins = array_merge( $deactivated_plugins, $deactivated_gutenberg );
     1683            update_site_option( 'wp_force_deactivated_plugins', $deactivated_plugins );
     1684        } else {
     1685            $deactivated_plugins = get_option( 'wp_force_deactivated_plugins', array() );
     1686            $deactivated_plugins = array_merge( $deactivated_plugins, $deactivated_gutenberg );
     1687            update_option( 'wp_force_deactivated_plugins', $deactivated_plugins );
     1688        }
    16751689        deactivate_plugins( array( 'gutenberg/gutenberg.php' ), true );
    16761690    }
Note: See TracChangeset for help on using the changeset viewer.