Skip to content

Instantly share code, notes, and snippets.

@man4toman
Last active March 15, 2019 12:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save man4toman/66dcfbe36ab143d9cc8c53e25d641ec3 to your computer and use it in GitHub Desktop.
Save man4toman/66dcfbe36ab143d9cc8c53e25d641ec3 to your computer and use it in GitHub Desktop.
Finding WordPress Administrator User IDs
<?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