Make WordPress Core


Ignore:
Timestamp:
06/30/2021 12:20:52 AM (5 years 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.