mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
Plugins: Introduce singular capabilities for activating and deactivating individual plugins.
This introduces the following meta capabilities: * `activate_plugin` * `deactivate_plugin` * `deactivate_plugins` The singular `activate_plugin` and `deactivate_plugin` capabilities are used along with the corresponding plugin name when determining whether or not a user can activate or deactivate an individual plugin. The plural `deactivate_plugins` capability is used in place of the existing `activate_plugins` capability when determining whether a user can deactivate plugins. Each of these new meta capabilities map to the existing `activate_plugins` primitive capability, which means there is no change in existing behaviour, but plugins can now filter the capabilities required to activate and deactivate individual plugins. Fixes #38652 git-svn-id: https://develop.svn.wordpress.org/trunk@41290 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -29,8 +29,9 @@ if ( $action ) {
|
||||
|
||||
switch ( $action ) {
|
||||
case 'activate':
|
||||
if ( ! current_user_can('activate_plugins') )
|
||||
wp_die(__('Sorry, you are not allowed to activate plugins for this site.'));
|
||||
if ( ! current_user_can( 'activate_plugin', $plugin ) ) {
|
||||
wp_die( __( 'Sorry, you are not allowed to activate this plugin.' ) );
|
||||
}
|
||||
|
||||
if ( is_multisite() && ! is_network_admin() && is_network_only_plugin( $plugin ) ) {
|
||||
wp_redirect( self_admin_url("plugins.php?plugin_status=$status&paged=$page&s=$s") );
|
||||
@@ -88,6 +89,10 @@ if ( $action ) {
|
||||
if ( is_plugin_active( $plugin ) || ( is_multisite() && is_network_only_plugin( $plugin ) ) ) {
|
||||
unset( $plugins[ $i ] );
|
||||
}
|
||||
// Only activate plugins which the user can activate.
|
||||
if ( ! current_user_can( 'activate_plugin', $plugin ) ) {
|
||||
unset( $plugins[ $i ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,8 +151,9 @@ if ( $action ) {
|
||||
exit;
|
||||
|
||||
case 'error_scrape':
|
||||
if ( ! current_user_can('activate_plugins') )
|
||||
wp_die(__('Sorry, you are not allowed to activate plugins for this site.'));
|
||||
if ( ! current_user_can( 'activate_plugin', $plugin ) ) {
|
||||
wp_die( __( 'Sorry, you are not allowed to activate this plugin.' ) );
|
||||
}
|
||||
|
||||
check_admin_referer('plugin-activation-error_' . $plugin);
|
||||
|
||||
@@ -167,8 +173,9 @@ if ( $action ) {
|
||||
exit;
|
||||
|
||||
case 'deactivate':
|
||||
if ( ! current_user_can('activate_plugins') )
|
||||
wp_die(__('Sorry, you are not allowed to deactivate plugins for this site.'));
|
||||
if ( ! current_user_can( 'deactivate_plugin', $plugin ) ) {
|
||||
wp_die( __( 'Sorry, you are not allowed to deactivate this plugin.' ) );
|
||||
}
|
||||
|
||||
check_admin_referer('deactivate-plugin_' . $plugin);
|
||||
|
||||
@@ -192,8 +199,9 @@ if ( $action ) {
|
||||
exit;
|
||||
|
||||
case 'deactivate-selected':
|
||||
if ( ! current_user_can('activate_plugins') )
|
||||
if ( ! current_user_can( 'deactivate_plugins' ) ) {
|
||||
wp_die(__('Sorry, you are not allowed to deactivate plugins for this site.'));
|
||||
}
|
||||
|
||||
check_admin_referer('bulk-plugins');
|
||||
|
||||
@@ -204,6 +212,14 @@ if ( $action ) {
|
||||
} else {
|
||||
$plugins = array_filter( $plugins, 'is_plugin_active' );
|
||||
$plugins = array_diff( $plugins, array_filter( $plugins, 'is_plugin_active_for_network' ) );
|
||||
|
||||
foreach ( $plugins as $i => $plugin ) {
|
||||
// Only deactivate plugins which the user can deactivate.
|
||||
if ( ! current_user_can( 'deactivate_plugin', $plugin ) ) {
|
||||
unset( $plugins[ $i ] );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if ( empty($plugins) ) {
|
||||
wp_redirect( self_admin_url("plugins.php?plugin_status=$status&paged=$page&s=$s") );
|
||||
|
||||
Reference in New Issue
Block a user