Skip to content

Instantly share code, notes, and snippets.

@mariokerkhof
Created February 3, 2016 16:17
Show Gist options
  • Save mariokerkhof/85198fc56d3702de9bf7 to your computer and use it in GitHub Desktop.
Save mariokerkhof/85198fc56d3702de9bf7 to your computer and use it in GitHub Desktop.
// Filter to fix the Post Author Dropdown
add_filter('wp_dropdown_users', 'theme_post_author_override');
function theme_post_author_override($output)
{
global $post, $user_ID;
// return if this isn't the theme author override dropdown
if (!preg_match('/post_author_override/', $output)) return $output;
// return if we've already replaced the list (end recursion)
if (preg_match ('/post_author_override_replaced/', $output)) return $output;
// replacement call to wp_dropdown_users
$output = wp_dropdown_users(array(
'echo' => 0,
'name' => 'post_author_override_replaced',
'selected' => empty($post->ID) ? $user_ID : $post->post_author,
'include_selected' => true
));
// put the original name back
$output = preg_replace('/post_author_override_replaced/', 'post_author_override', $output);
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment