REST API, get user role?

This is totally possible by registering your own rest field into the response. Here’s some documentation on modifying response data. https://developer.wordpress.org/rest-api/extending-the-rest-api/modifying-responses/ Here’s how to add roles to the endpoint: function get_user_roles($object, $field_name, $request) { return get_userdata($object[‘id’])->roles; } add_action(‘rest_api_init’, function() { register_rest_field(‘user’, ‘roles’, array( ‘get_callback’ => ‘get_user_roles’, ‘update_callback’ => null, ‘schema’ => array( ‘type’ => ‘array’ … Read more

Confusion with adding meta capabilities to a role after registering a Custom Post Type with corresponding ‘capability_type’ parameter

Have you tried defining the capabilities inside the external_roles_post_type_init() function? After the ‘capability_type’ => array(‘external_role’, ‘external_roles’), try add this ‘capabilities’ => array( ‘publish_posts’ => ‘publish_external_roles’, ‘edit_posts’ => ‘edit_external_roles’, ‘edit_others_posts’ => ‘edit_others_external_roles’, ‘delete_posts’ => ‘delete_external_roles’, ‘delete_others_posts’ => ‘delete_others_external_roles’, ‘read_private_posts’ => ‘read_private_external_roles’, ‘edit_post’ => ‘edit_external_role’, ‘delete_post’ => ‘delete_external_role’, ‘read_post’ => ‘read_external_role’, ), as another argument of the … Read more

Temporarily give ‘manage_options’ capability

Good question! The capability checking is probably done quite early in the loading process. By looking at /wp-admin/users.php you can tell that one of the first things to happen is current_user_can( ‘list_users’ ), so that one is clearly needed or you’ll get the “Cheatin’ uh?” warning. But right before that, /wp-admin/admin.php is included, and at … Read more

Creating custom user roles

Adding a role is very simple. Creating custom capabilities is a little bit more to wrap your head around. When you register your custom post type, you define your capabilities for it. Essentially it is an array of “what do you want to count as this?”. My example below will clarify this statement. $caps = … Read more

How to auto-translate custom user roles?

The translate_user_role function is just a wrapper for translate_with_gettext_context, defining the context ‘User role’. In this last function, there is the filter hook gettext_with_context, which provides the context as well as the currently used domain. So we could do this: function wpdev_141551_translate_user_roles( $translations, $text, $context, $domain ) { $plugin_domain = ‘plugin-text-domain’; $roles = array( ‘Someone’, … Read more

How to Change the Entire WordPress Admin panel Look and Feel?

Here’s a great codex article on the topic of creating administration theme: http://codex.wordpress.org/Creating_Admin_Themes And back to your question, you will want to load different stylesheets for different user roles, so you have to check who the current user is. Pay attention, the check is done using current_user_can() function and checking for administrator is not being … Read more

How to remove administrator role in settings -> general -> New User Default Role?

Okay, this looks tricky, but I think it’s possible. The user-new.php file calls wp_dropdown_roles() to output the list of roles. The wp_dropdown_roles() function calls get_editable_roles() to get the list of roles to output. The get_editable_roles() function has a filter, editable_roles. So, you should be able to add a filter for editable_roles, such that, if the … Read more

Restrict custom post type view by user role

Every role has capabilities. Here is a simple contributor to our endeavor: (he just writes and edits) add_role(‘contributor’, ‘Contributor’, array( ‘read’ => true, ‘edit_posts’ => true, ‘delete_posts’ => false, )); Now he has a new capability (he can edit other peoples posts) function add_capability() { $role = get_role(‘contributor’); $role->add_cap(‘edit_others_posts’); } add_action(‘admin_init’, ‘add_capability’); Now to add … Read more