Skip to content

Instantly share code, notes, and snippets.

@LinzardMac
Created March 26, 2015 19:20

Revisions

  1. LinzardMac created this gist Mar 26, 2015.
    37 changes: 37 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@

    /**
    * override output of author drop down to include ALL user roles
    */
    add_filter('wp_dropdown_users', 'include_all_users');
    function include_all_users($output)
    {
    //set the $post global for checking user against author
    global $post;
    $users = get_users();
    $current_user = wp_get_current_user();

    $output = '<select id="post_author_override" name="post_author_override" class="">';

    //Loop through each user
    foreach($users as $user){

    //if the post's author matches the user ID, set it to "selected" so it will appear when you load the page
    //else, set as empty
    // In doing tests, it seems as though new posts set the "author" to the current user automatically

    if($post->post_author == $user->ID){

    $select = 'selected';

    }else{

    $select = '';
    } // end if post_author == user id

    //output an <option> tag with each user's info and output results of $select
    $output .= '<option value="'.$user->ID.'"'.$select.'>'.$user->user_login.'</option>';
    } //end foreach
    $output .= '</select>';

    return $output;
    }