• 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;

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter fbendz

    (@fbendz)

    Note: I’m using WordPress 2.0.5.

    [mod note: Moved to Requests and Feedback]

    The problem seems to lie in the fact that the wp_list_authors function relies on the admin’s actual user login name rather than a user ID.

    First, open \wp-includes\author-template.php.

    If you haven’t messed around with this file before, what you will be looking for is at Line 189:
    $authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users " . ($exclude_admin ? "WHERE user_login <> 'admin' " : '') . "ORDER BY display_name");'

    Now, there are two ways to fix the problem. The first way is to just change the username the query looks for (admin) to whatever the actual login name your admin uses. For example:
    $authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users " . ($exclude_admin ? "WHERE user_login <> 'steve' " : '') . "ORDER BY display_name");'

    The second way is to change the query so that it searches for the default admin user ID, which is ‘1’. To accomplish this, change Line 189 to:
    $authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users " . ($exclude_admin ? "WHERE ID <> '1' " : '') . "ORDER BY display_name");'

    Hope that helps. ??

    its a 4 month old post ?? but it might help someone else

    Yes! It totally helped me out, thank you very much Josethematador! I needed to have wp_list_authors disregard user ids 1-3, and a simple modification to your code did the trick.

    Am I correct in assuming it’s better not to make the changes directly to author-template.php, but to create a simple plugin with the modified code?

    Such a plugin would be very helpful. I’m currently using WordPress 2.3.1 with phpBB and WP-United (which integrates login).

    WP-United currently does not support editing of the profile from WP, so I need to go to the database to input the user’s display name because I need it for the article’s byline. Then, I also need to input the first and last name in the database so the list of authors in author’s page would show their full name.

    If the function would instead call only the display name, I won’t have to input the user’s first and last name thru mySQL.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Admin does not hide’ is closed to new replies.