Tell us what you are trying to do? I have a new user and I have a new custom role for this user.. I tried to assign a custom post to this user but in the dropdown where I have to select the Author I can view all other users except this user. However the user exists in the ALL USERS view but is not visible in the Authors dropdown view.
Is there any documentation that you are following?
Is there a similar example that we can see?
What is the link to your site? hidden link
Hi, you can use a small custom code snippet to allow Users from a custom role to be shown in the author dropdown. Another Toolset user had a similar question in the forum post here: https://toolset.com/forums/topic/author-dropdown-and-custom-roles/
Here is the code snippet - you must replace member with the slug of the custom role, but you probably should not make any other changes.
function wpdocs_add_members_to_dropdown( $query_args, $r ) {
$query_args['role'] = array('member');
// Unset the 'who' as this defaults to the 'author' role
unset( $query_args['who'] );
return $query_args;
}
add_filter( 'wp_dropdown_users_args', 'wpdocs_add_members_to_dropdown', 10, 2 );
You can add this code in a child theme's functions.php file, or you can create a new code snippet in wp-admin > Toolset > Settings, in the Custom Code tab. Let me know if I misunderstood the request or if you have problems implementing this code.
Hi Christian
Thanks for the accurate assessment and solution..:-).. you were absolutely right about what I wanted..
There is one issue related to adding the code in the Custom Code Tab where it gave me this message below
Please advise what I need to put in the wp-config for the future
for the current code I added it manually.
Coming back to the AUTHOR dropdown, it's interesting to note that the user who had a similar query (The link that you sent to me.. https://toolset.com/forums/topic/author-dropdown-and-custom-roles/) ... She seemed to add all the permissions that are normally assigned to AUTHOR to the new custom role she had created. I have copied all permissions from SUBSCRIBER Role so basically not a lot of permissions were provided. I had 2 options.. Either follow what she did and update the custom role permission to mimic those of the AUTHORs or add multiple roles to the same user.. so the user had the custom role permissions as well as the AUTHOR role permissions.. it seemed to work fine for me..
Could you please advise which of the two (Set the right permission of the custom role OR Add multiple roles to user based on a combination of permissions ) is a better method and why?
Now I have another thread with Shane here.. https://toolset.com/forums/topic/user-permission-to-view-and-edit-custom-posts/ .. so I will ask him the other questions on that post.. and not mix the two...;-)..
But I had one query more for you.. I didn't know till Shane told me that I could have a new front-end option to edit posts and it's a whole new thing for me.. I always assumed that the only way to edit would be to have the backend admin access and I'd have to limit the menu permissions.. but I prefer the frontend as it's a whole lot non-intrusive.
Is there a link or some documentation for me to know which is a better option (backend editing or frontend editing for custom posts)? Or if you can let me know, I'll just take your word for it..;-)..
Regards,
Alim
There is one issue related to adding the code in the Custom Code Tab where it gave me this message below
Please advise what I need to put in the wp-config for the future
for the current code I added it manually.
I'm sorry but I do not understand what you are saying. Can you provide a bit more information? Perhaps you could share a screenshot of the error?
Could you please advise which of the two (Set the right permission of the custom role OR Add multiple roles to user based on a combination of permissions ) is a better method and why?
Some pieces of custom code you'll find on the site here were written when Access only supported one role per User. Now that multiple roles are supported, we have noticed that some of those custom code snippets are no longer reliable. For that reason, I prefer to use one role and manage all capabilities in that role as needed. See this ticket: https://toolset.com/forums/topic/block-completely-backend-access-to-a-user-role/
// Hide the admin area from all Users
// with the User role "hide-from-role-slug"
$user = wp_get_current_user();
$roles = $user->roles; // now you have an array of all the User's roles
$role = array_shift($roles); // this picks the first role in an array of roles
if ( $role == 'hide-from-role-slug' && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
wp_redirect( site_url() );
exit;
}
Instead, the code should loop over all the roles in the array and test each role, not just assume that only one role will exist.
Is there a link or some documentation for me to know which is a better option (backend editing or frontend editing for custom posts)? Or if you can let me know, I'll just take your word for it..;-)..
Let's discuss this in a separate ticket.
Hi Christian...:-)..
I'm sorry but I do not understand what you are saying. Can you provide a bit more information? Perhaps you could share a screenshot of the error?
Am attaching a screenshot to show you the error.. Please check the text with the yellow highlight border on the left.. you would notice that I can't add or edit anything in the field...
Regards,
Alim
I have split the custom code snippet issue into a separate ticket so we can discuss the problem.
My issue is resolved now. Thank you!
Thanks again Christian.. In my opinion should be a default feature rather than having to add a code to customize...:-).. and maybe if someone doesn't want to provide the option of adding custom role users as authors you could have a checkbox option to disable it.. just a suggestion...:-)..
Have a nice day..:-)..
Regards,
Alim