Last active
April 28, 2023 08:32
-
-
Save mattiasghodsian/aa6f86ec83f1f87293125796f85bfa6f to your computer and use it in GitHub Desktop.
[Wordpress] Add more users to Auther box
This file contains hidden or 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
| /** | |
| * Add more users to Auther box | |
| * Author: Mattias Ghodsian | |
| * Donate a cup of coffee: https://www.buymeacoffee.com/mattiasghodsian | |
| * Donate Eth: 0xBBB96204E45D11C9799c6B12E6eE6F0d4A071Ef5 | |
| */ | |
| add_filter('wp_dropdown_users', 'add_users_to_dropdown_users'); | |
| function add_users_to_dropdown_users() | |
| { | |
| global $post; // remove if not needed | |
| //global $post is available here, hence you can check for the post type here | |
| $admin_users = get_users('role=administrator'); | |
| $merchant_users = get_users('role=merchant'); | |
| $users = array_merge($admin_users, $merchant_users); | |
| echo'<select id="post_author_override" name="post_author_override" class="">'; | |
| foreach($users as $user) | |
| { | |
| echo '<option value="'.$user->ID.'"'; | |
| if ($post->post_author == $user->ID){ echo 'selected="selected"'; } | |
| echo'>'; | |
| echo $user->first_name.' '.$user->lastname.'('.$user->user_email.')</option>'; | |
| } | |
| echo'</select>'; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment