Skip to content

Instantly share code, notes, and snippets.

@marcelo2605
Forked from LinzardMac/gist:4b4bcbef09d72b777619
Last active September 25, 2015 17:13
Show Gist options
  • Save marcelo2605/b195243976cb9c7f3f53 to your computer and use it in GitHub Desktop.
Save marcelo2605/b195243976cb9c7f3f53 to your computer and use it in GitHub Desktop.
[WordPress] Override author drop down to include all users from all roles/ caps in post creation screens
/**
* 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();
$currentScreen = get_current_screen();
$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
$select = "";
// check if not admin user page
if( $currentScreen->id !== "users" ) {
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment