Skip to content

Commit

Permalink
Update admin/load.php, more graceful error exiting if user lacks perm…
Browse files Browse the repository at this point in the history
…issions to deactivate plugin.

Co-authored-by: Felix Arntz <[email protected]>
  • Loading branch information
10upsimon and felixarntz authored Nov 8, 2023
1 parent 2246e74 commit a2e1c1d
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions admin/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,13 +575,17 @@ function perflab_deactivate_plugin() {
// The plugin being deactivated.
$plugin = sanitize_text_field( $_GET['plugin'] );

if ( check_admin_referer( "perflab_deactivate_plugin_{$plugin}" ) && current_user_can( 'deactivate_plugin', $plugin ) ) {
// Deactivate the plugin in question and return to prior screen.
deactivate_plugins( $plugin );
$referer = wp_get_referer();
if ( wp_safe_redirect( $referer ) ) {
exit;
}
check_admin_referer( "perflab_deactivate_plugin_{$plugin}" )

if ( ! current_user_can( 'deactivate_plugin', $plugin ) ) {
wp_die( __( 'Sorry, you are not allowed to deactivate this plugin.', 'default' ) );
}

// Deactivate the plugin in question and return to prior screen.
deactivate_plugins( $plugin );
$referer = wp_get_referer();
if ( wp_safe_redirect( $referer ) ) {
exit;
}
}

Expand Down

0 comments on commit a2e1c1d

Please sign in to comment.