Created
March 26, 2015 19:20
-
-
Save LinzardMac/4b4bcbef09d72b777619 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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment