Admin does not hide
-
I’m using the list_authors function to display posts by author in the side menu. The problem is that even though exclude_admin is set to true (1), that very account is still listed. I found out what the error was, and it is that the admin account has a different name than ‘admin’ (to prevent hackers from finding out the login name of the administrator). Because the function only excludes users where user_login = ‘admin’ I had to hack the SQL query and exchange ‘admin’ with the login name of the actual admin.
However, this hack is unsatisfactory. I would like to exclude any user who’s status is administrator. How do I change the code to achieve this?
Another unsatisfactory feature is that it is always the login name that is listed, not the display name. I corrected this by replacing $name with $author->display_name on line 200 in the file template-author-functions.php (the line number is with no word-wrapping in the editor). I didn’t dare to change $name from $author->nickname to $author display_name on line 189 because that would effect several other things in the code.
My suggestion is that a new parameter, $show_displayname is added to the function in the next version. If set to true, $name gets the value of $author->display_name instead of author_nickname, just as the parameter $show_fullname works today:
function list_authors($optioncount = false, $exclude_admin = true, $show_fullname = false, $show_displayname = true, $hide_empty = true, $feed = '', $feed_image = '') {
global $wpdb;
$query = "SELECT ID, user_nicename from $wpdb->users " . ($exclude_admin ? "WHERE user_login <> 'admin' " : '') . "ORDER BY display_name";
$authors = $wpdb->get_results($query);
foreach ( $authors as $author ) {
$author = get_userdata( $author->ID );
$posts = get_usernumposts($author->ID);
$name = $author->nickname;
if ( $show_fullname && ($author->first_name != '' && $author->last_name != '') )
$name = "$author->first_name $author->last_name";
if ($show_displayname && $author->display_name != '') $name = author->display_name;
- The topic ‘Admin does not hide’ is closed to new replies.