I was successfully using this excellent contributors function to generate a list of the users on my site with gravatar photo.. UNTIL the client decided they don't want to use gravatar and would rather use images hosted on their own site. It also came out that they will have many other roles on the site besides author, and "WHERE NOT" in the query isn't going to suffice anymore.

Can someone help me with 2 parts.. Adapt this function to limit to "Author" role AND use the user's first name & last name to customize the image link so I can pull in their image from /uploads? This would be used outside of the loop.

I'm currently using $curauth in the loop to append the author's first and last name to an image link, which works well, and the image is named JohnSmith.jpg in the uploads folder.

My SQL and PHP is weak but I am thinking:

select id, firstName, lastName from users WHERE Role=Author;

Then, replace

 echo get_avatar($author->ID);


 echo '<img src=/uploads/author-' . $author->firstName,lastName; . '.jpg />;

I assume there will be a join to get the user role and I'm not quite sure what the field is called.. Below is the contributors function. Any help with this would really be appreciated!

function contributors() {
global $wpdb;

$authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users WHERE NOT ID = '1' ORDER BY display_name");

foreach($authors as $author) {
    echo "<li>";
    echo "<a href=\"".get_bloginfo('url')."/?author=";
    echo $author->ID;
    echo "\">";
    echo get_avatar($author->ID);
    echo "</a>";
    echo '<div>';
    echo "<a href=\"".get_bloginfo('url')."/?author=";
    echo $author->ID;
    echo "\">";
    the_author_meta('display_name', $author->ID);
    echo "</a>";
    echo "</div>";
    echo "</li>";


1 Answer 1


A join to get the user role? I don't think so.

Since you're into doing your own PHP (from the examples you've provided) do more research on the built in functions for what you're looking to do in the WordPress Codex.

As far as creating new roles the code below copies the Administrator role, removes any capabilities you woudn't want in your new custom role and lastly names your new role:

$newrole = get_role('administrator'); //choice of Administrator, Editor, Author, 

Contributor, Subscriber - http://codex.wordpress.org/Roles_and_Capabilities

$caps = $newrole->capabilities;

// Unset the capabilities you don’t want in the new role.

// unset($caps['edit_theme_options']);

// Add the new role.
add_role('Master Editor', 'Master Editor', $caps); // your new role "Master Editor"

or add a capability to an existing role.

function add_cap_to_editor() 
            $role = get_role( 'editor' ); // pick up role to edit the editor role   
            $role->add_cap( 'edit_users' );
            $role->add_cap( 'create_users' );
        add_action( 'admin_init', 'add_cap_to_editor');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.