Add subscribers authors in WordPress


Add subscribers as authors in WordPress.

Add the following code to your theme function.php

NOTE: THIS ONLY WORKS WHEN ADDING AN AUTHOR. DEACTIVATE WHEN NOT ADDING SUBSCRIBER AS AUTHOR ON POST.

add_filter('wp_dropdown_users', 'MySwitchUser');
function MySwitchUser($output)
{

    //global $post is available here, hence you can check for the post type here
    $users = get_users('role=subscriber');

    $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;
}​

Did you find this article useful?