Skip to content

WordPress – select which user roles can be author of a post

You may want to select users as authors which you do not want to allow the direct editing or creating of posts.

function wp_author_users() {
    global $post;
     * User roles you want to be author of posts
    $roles = array(
        'administrator', 'contributor' , 'subscriber'
    $users = array();
    foreach($roles as $role) {
        $users = array_merge($users, get_users('role='.$role));
    $output = "<select id=\"post_author_override\" name=\"post_author_override\" class=\"\">";
     * Leave the admin in the list
    $output .= "<option value=\"1\">Admin</option>";
    foreach($users as $user) {
        $sel = ($post->post_author == $user->ID)?"selected='selected'":'';
        $output .= '<option value="'.$user->ID.'"'.$sel.'>'.$user->user_login.'</option>';
    $output .= "</select>";
    return $output; 
add_filter('wp_dropdown_users', 'wp_author_users');


10 years + experience in web development working with lots of different technology.

Published inPHPWordPress

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *