Advertisement
Innate

Wordpress Dropdown Users Filter

Jan 16th, 2012
322
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. add_action('admin_head', 'replace_post_meta_author');
  2.  
  3. function replace_post_meta_author() {
  4. $screen = get_current_screen();
  5. if($screen->id == 'post') {
  6. add_filter('wp_dropdown_users', 'showme_dropdown_users');
  7. function showme_dropdown_users( $args = '' ) {
  8. $post = get_post();
  9. $selected = $post->post_author;
  10. $siteusers = get_users('orderby=nicename&order=ASC'); // you can pass filters and option
  11. $re = '';
  12. if (count($siteusers) > 0){
  13. $re = '<select name="post_author_override" id="post_author_override">';
  14. foreach ($siteusers as $user) {
  15. $re .= '<option value="' . $user->ID . '">'.$user->user_nicename . ' ('.$user->user_email .')</option>';
  16. }
  17. $re .= '</select>';
  18. $re = str_replace('value="' . $selected . '"','value="' . $selected . '" selected="selected"', $re );
  19. }
  20. echo $re;
  21. }
  22. }
  23. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement