mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-08 22:54:36 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@51266 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -2473,3 +2473,88 @@ function paused_plugins_notice() {
|
||||
__( 'Go to the Plugins screen' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders an admin notice when a plugin was deactivated during an update.
|
||||
*
|
||||
* Displays an admin notice in case a plugin has been deactivated during an
|
||||
* upgrade due to incompatibility with the current version of WordPress.
|
||||
*
|
||||
* @since 5.8.0
|
||||
* @access private
|
||||
*
|
||||
* @global string $pagenow
|
||||
* @global string $wp_version
|
||||
*/
|
||||
function deactivated_plugins_notice() {
|
||||
if ( 'plugins.php' === $GLOBALS['pagenow'] ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! current_user_can( 'activate_plugins' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$blog_deactivated_plugins = get_option( 'wp_force_deactivated_plugins' );
|
||||
$site_deactivated_plugins = array();
|
||||
|
||||
if ( false === $blog_deactivated_plugins ) {
|
||||
// Option not in database, add an empty array to avoid extra DB queries on subsequent loads.
|
||||
update_option( 'wp_force_deactivated_plugins', array() );
|
||||
}
|
||||
|
||||
if ( is_multisite() ) {
|
||||
$site_deactivated_plugins = get_site_option( 'wp_force_deactivated_plugins' );
|
||||
if ( false === $site_deactivated_plugins ) {
|
||||
// Option not in database, add an empty array to avoid extra DB queries on subsequent loads.
|
||||
update_site_option( 'wp_force_deactivated_plugins', array() );
|
||||
}
|
||||
}
|
||||
|
||||
if ( empty( $blog_deactivated_plugins ) && empty( $site_deactivated_plugins ) ) {
|
||||
// No deactivated plugins.
|
||||
return;
|
||||
}
|
||||
|
||||
$deactivated_plugins = array_merge( $blog_deactivated_plugins, $site_deactivated_plugins );
|
||||
|
||||
foreach ( $deactivated_plugins as $plugin ) {
|
||||
if ( ! empty( $plugin['version_compatible'] ) && ! empty( $plugin['version_deactivated'] ) ) {
|
||||
$explanation = sprintf(
|
||||
/* translators: 1: Name of deactivated plugin, 2: Plugin version deactivated, 3: Current WP version, 4: Compatible plugin version */
|
||||
__( '%1$s %2$s was deactivated due to incompatibility with WordPress %3$s, please upgrade to %1$s %4$s or later.' ),
|
||||
$plugin['plugin_name'],
|
||||
$plugin['version_deactivated'],
|
||||
$GLOBALS['wp_version'],
|
||||
$plugin['version_compatible']
|
||||
);
|
||||
} else {
|
||||
$explanation = sprintf(
|
||||
/* translators: 1: Name of deactivated plugin, 2: Plugin version deactivated, 3: Current WP version */
|
||||
__( '%1$s %2$s was deactivated due to incompatibility with WordPress %3$s.' ),
|
||||
$plugin['plugin_name'],
|
||||
! empty( $plugin['version_deactivated'] ) ? $plugin['version_deactivated'] : '',
|
||||
$GLOBALS['wp_version'],
|
||||
$plugin['version_compatible']
|
||||
);
|
||||
}
|
||||
|
||||
printf(
|
||||
'<div class="notice notice-warning"><p><strong>%s</strong><br>%s</p><p><a href="%s">%s</a></p></div>',
|
||||
sprintf(
|
||||
/* translators: %s: Name of deactivated plugin */
|
||||
__( '%s plugin deactivated during WordPress upgrade.' ),
|
||||
$plugin['plugin_name']
|
||||
),
|
||||
$explanation,
|
||||
esc_url( admin_url( 'plugins.php?plugin_status=inactive' ) ),
|
||||
__( 'Go to the Plugins screen' )
|
||||
);
|
||||
}
|
||||
|
||||
// Empty the options.
|
||||
update_option( 'wp_force_deactivated_plugins', array() );
|
||||
if ( is_multisite() ) {
|
||||
update_site_option( 'wp_force_deactivated_plugins', array() );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user