Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

with

 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>";
}

}

share|improve this question

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['activate_plugins']);
//unset($caps['edit_plugins']);
//unset($caps['update_plugins']);
//unset($caps['delete_plugins']);
//unset($caps['install_plugins']);
//unset($caps['delete_users']);
//unset($caps['import']);
//unset($caps['create_users']);
unset($caps['edit_users']);
unset($caps['edit_dashboard']);
unset($caps['update_core']);
unset($caps['switch_themes']);

// 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');
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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