Last active
March 15, 2019 12:01
-
-
Save man4toman/66dcfbe36ab143d9cc8c53e25d641ec3 to your computer and use it in GitHub Desktop.
Finding WordPress Administrator User IDs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function get_admins_user_ids(){ | |
global $wpdb; | |
//Select all users ID | |
$all_users = $wpdb->get_col("SELECT ID FROM $wpdb->users ORDER BY ID"); | |
$adminsArray = array(); | |
foreach ( $all_users as $uid ) { | |
//Get all users that have administrator role | |
if(get_userdata($uid)->roles[0] == 'administrator'){ | |
$adminsArray[] = $uid; | |
} | |
} | |
return $adminsArray; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment