Skip to content

Commit

Permalink
Sitewide plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
hellofromtonya committed Feb 7, 2024
1 parent af32b78 commit 1dc3bb9
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 30 deletions.
40 changes: 21 additions & 19 deletions src/wp-admin/includes/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2616,27 +2616,29 @@ function _render_admin_notice_for_incompatible_plugins( $incompatible_plugins )
return;
}

foreach ( $incompatible_plugins as $plugin ) {
// Skip if information is missing.
if ( empty( $plugin['version_compatible'] ) || empty( $plugin['version_deactivated'] ) ) {
continue;
}
foreach ( $incompatible_plugins as $plugins ) {
foreach ( $plugins as $plugin ) {
// Skip if information is missing.
if ( empty( $plugin['version_compatible'] ) || empty( $plugin['version_deactivated'] ) ) {
continue;
}

$explanation = sprintf(
$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']
);
__( '%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']
);

$message = sprintf(
'%s</p><p><a href="%s">%s</a>',
$explanation,
esc_url( admin_url( 'plugins.php?plugin_status=inactive' ) ),
__( 'Go to the Plugins screen' )
);
wp_admin_notice( $message, array( 'type' => 'warning' ) );
$message = sprintf(
'%s</p><p><a href="%s">%s</a>',
$explanation,
esc_url( admin_url( 'plugins.php?plugin_status=inactive' ) ),
__( 'Go to the Plugins screen' )
);
wp_admin_notice( $message, array( 'type' => 'warning' ) );
}
}
}
41 changes: 30 additions & 11 deletions src/wp-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,10 @@
global $_found_incompatible_for_core_plugins, $_is_plugin_compatible_with_wp, $_handle_incompatible_for_core_plugins;

// Found incompatible for-core plugins.
$_found_incompatible_for_core_plugins = array();
$_found_incompatible_for_core_plugins = array(
'sitewide_plugins' => array(),
'single_plugins' => array(),
);

/**
* Checks if the given plugin is compatible with this WordPress version.
Expand Down Expand Up @@ -486,7 +489,8 @@
}

// Found an incompatible for-core plugin. Add it to the found global for later batch processing.
$_found_incompatible_for_core_plugins[ $plugin ] = array(
$key = $is_network ? 'sitewide_plugins' : 'single_plugins';
$_found_incompatible_for_core_plugins[ $key ][ $plugin ] = array(
'plugin_absolute_path' => $plugin_absolute_path,
'plugin_name' => $plugin_data['Name'],
'version_deactivated' => $plugin_data['Version'],
Expand All @@ -511,20 +515,35 @@
$_handle_incompatible_for_core_plugins = static function () {
global $_found_incompatible_for_core_plugins;

$active_plugins = (array) get_option( 'active_plugins', array() );
$active_plugins_by_plugin = array_flip( $active_plugins );
if ( ! empty( $_found_incompatible_for_core_plugins['single_plugins'] ) ) {
$active_plugins = (array) get_option( 'active_plugins', array() );
$active_plugins_by_plugin = array_flip( $active_plugins );

// Remove each of the found incompatible plugins from the "active_plugins" option.
foreach ( $_found_incompatible_for_core_plugins['single_plugins'] as $plugin => $plugin_info ) {
unset( $active_plugins[ $active_plugins_by_plugin[ $plugin ] ] );
}

// Remove each of the found incompatible plugins from the "active_plugins" option.
foreach ( $_found_incompatible_for_core_plugins as $plugin_slug => $plugin ) {
unset( $active_plugins[ $active_plugins_by_plugin[ $plugin_slug ] ] );
// Update the option, which no longer includes the incompatible plugins.
update_option( 'active_plugins', $active_plugins );
}

// Update the 'active plugins' option, which no longer includes the incompatible plugins.
update_option( 'active_plugins', $active_plugins );
if ( ! empty( $_found_incompatible_for_core_plugins['sitewide_plugins'] ) ) {
$active_plugins = (array) get_site_option( 'active_sitewide_plugins', array() );
$active_plugins_by_plugin = array_flip( $active_plugins );

// Remove each of the found incompatible plugins from the "active_sitewide_plugins" option.
foreach ( $_found_incompatible_for_core_plugins['sitewide_plugins'] as $plugin => $plugin_info ) {
unset( $active_plugins[ $active_plugins_by_plugin[ $plugin ] ] );
}

// Update the option, which no longer includes the incompatible plugins.
update_site_option( 'active_sitewide_plugins', $active_plugins );
}

// Update the list of incompatible plugins to notify user in the admin.
$admin_notices_handler = static function () use ( $_found_incompatible_for_core_plugins ) {
_render_notice_for_incompatible_plugins( $_found_incompatible_for_core_plugins );
_render_admin_notice_for_incompatible_plugins( $_found_incompatible_for_core_plugins );
};
add_action( 'admin_notices', $admin_notices_handler, 5 );
};
Expand Down Expand Up @@ -556,7 +575,7 @@
*
* @since 6.5.0
*/
if ( ! $_is_plugin_compatible_with_wp( $network_plugin ) ) {
if ( ! $_is_plugin_compatible_with_wp( $network_plugin, true ) ) {
continue;
}

Expand Down

0 comments on commit 1dc3bb9

Please sign in to comment.