Skip to content

Commit

Permalink
Exclude all super admins from the list of admins.
Browse files Browse the repository at this point in the history
  • Loading branch information
soderlind committed Aug 21, 2023
1 parent e810fa0 commit c00b42b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ It's also possible to install the plugin via Composer:

## Changelog

### 1.0.3

- Exclude all super admins from the list of admins.

### 1.0.2

- Add Norwegian translation.
Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: super admin, multisite, admin, switch
Requires at least: 6.0
Tested up to: 6.3
Requires PHP: 7.3
Stable tag: 1.0.2
Stable tag: 1.0.3
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Expand All @@ -29,6 +29,9 @@ It lists all admins for the current site, except for the super admin., and creat

== Changelog ==

= 1.0.3 =
* Exclude all super admins from the list of admins.

= 1.0.2 =
* Add Norwegian translation.

Expand Down
22 changes: 18 additions & 4 deletions super-admin-switch-to-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Plugin URI: https://github.com/soderlind/super-admin-switch-to-admin
* GitHub Plugin URI: https://github.com/soderlind/super-admin-switch-to-admin
* Description: If you are logged in as a super admin, allows you to switch to a regular admin account on the current site.
* Version: 1.0.2
* Version: 1.0.3
* Author: Per Soderlind
* Author URI: https://soderlind.no
* Network: true
Expand Down Expand Up @@ -73,12 +73,12 @@ public function switch_to_admin() {
return;
}

// List all admins for the current site, except for the super admin.
// List all admins for the current site, except for the super admins.
$admins = get_users(
[
'blog_id' => \get_current_blog_id(),
'role' => 'administrator',
'exclude' => [ get_current_user_id() ],
'exclude' => $this->get_super_admins_ids(),
]
);

Expand All @@ -94,7 +94,6 @@ public function switch_to_admin() {
}
}


/**
* Admin notice.
*
Expand Down Expand Up @@ -125,6 +124,21 @@ public function admin_notice() {
</div>
<?php
}

/**
* Get super admins ids.
*
* @return array
*/
private function get_super_admins_ids() {
$super_admins = \get_super_admins();
$super_admins_ids = [];
foreach ( $super_admins as $super_admin ) {
$super_admins_ids[] = \get_user_by( 'login', $super_admin )->ID;
}
return $super_admins_ids;
}

}

new SuperAdminSwitchToAdmin();

0 comments on commit c00b42b

Please sign in to comment.