Skip to content

Instantly share code, notes, and snippets.

@todd-uams
Last active February 19, 2020 18:33
Show Gist options
  • Save todd-uams/15c79b9d9e4938866337cef049ee61f0 to your computer and use it in GitHub Desktop.
Save todd-uams/15c79b9d9e4938866337cef049ee61f0 to your computer and use it in GitHub Desktop.
Editor List
<?php
fb_list_authors(7, true);
function fb_list_authors($userlevel = 'all', $show_fullname = true) {
global $wpdb;
/*
all = Display all user
0 = subscriber
1 = contributor
2 = author
7 = editor
10 = administrator
*/
/*
if ( $userlevel == 'all' ) {
$author_subscriper = $wpdb->get_results("SELECT * from $wpdb->usermeta WHERE meta_key = 'wp_capabilities' AND meta_value = 'a:1:{s:10:\"subscriber\";b:1;}'");
foreach ( (array) $author_subscriper as $author ) {
$author = get_userdata( $author->user_id );
$userlevel = $author->wp_2_user_level;
$name = $author->nickname;
if ( $show_fullname && ($author->first_name != '' && $author->last_name != '') ) {
$name = "$author->first_name $author->last_name";
}
$link = '<li>' . $name . '</li>';
echo $link;
}
$i = 0;
while ( $i <= 10 ) {
$userlevel = $i;
$authors = $wpdb->get_results("SELECT * from $wpdb->usermeta WHERE meta_key = 'wp_user_level' AND meta_value = '$userlevel'");
foreach ( (array) $authors as $author ) {
$author = get_userdata( $author->user_id );
$userlevel = $author->wp_2_user_level;
$name = $author->nickname;
if ( $show_fullname && ($author->first_name != '' && $author->last_name != '') ) {
$name = "$author->first_name $author->last_name";
}
$link = '<li>' . $name . '</li>';
echo $link;
}
$i++;
}
} else {
*/
if ($userlevel == 0) {
$authors = $wpdb->get_results("SELECT * from $wpdb->usermeta WHERE meta_key = 'wp_capabilities' AND meta_value = 'a:1:{s:10:\"subscriber\";b:1;}'");
} else {
$authors = $wpdb->get_results("SELECT * from $wpdb->usermeta WHERE meta_key LIKE '%_capabilities' AND meta_value = 'a:1:{s:6:\"editor\";b:1;}'");
}
$author_exclude = array();
foreach ( (array) $authors as $author ) {
$authorid = $author->user_id;
$author = get_userdata( $author->user_id );
$userlevel = $author->wp_user_level;
$name = $author->nickname;
if ( $show_fullname && ($author->first_name != '' && $author->last_name != '') ) {
$name = "$author->first_name $author->last_name";
}
//$link = '<li><b>' .userlevelname($userlevel) . '</b></li>';
if (!in_array($authorid, $author_exclude)){
echo $link = '<li>' . $name . ' ['. $author->user_email .']</li>';
// echo $link;
$author_exclude[] = $authorid;
}
}
//}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment