kisukedeath

Custom roles missing from post author dropdown

Jul 13th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.89 KB | None | 0 0
  1. // Filter to fix the Post Author Dropdown
  2. add_filter('wp_dropdown_users', 'theme_post_author_override');
  3. function theme_post_author_override($output)
  4. {
  5.     global $post, $user_ID;
  6.      
  7.   // return if this isn't the theme author override dropdown
  8.   if (!preg_match('/post_author_override/', $output)) return $output;
  9.  
  10.   // return if we've already replaced the list (end recursion)
  11.   if (preg_match ('/post_author_override_replaced/', $output)) return $output;
  12.  
  13.   // replacement call to wp_dropdown_users
  14.     $output = wp_dropdown_users(array(
  15.       'echo' => 0,
  16.         'name' => 'post_author_override_replaced',
  17.         'selected' => empty($post->ID) ? $user_ID : $post->post_author,
  18.         'include_selected' => true
  19.     ));
  20.  
  21.     // put the original name back
  22.     $output = preg_replace('/post_author_override_replaced/', 'post_author_override', $output);
  23.  
  24.   return $output;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment