similar to Editor can create any new user except administrator

Simple all you need to do is edit this part of the code : function editable_roles( $roles ){ if( isset( $roles[‘administrator’] ) && !current_user_can(‘administrator’) ){ unset( $roles[‘administrator’]); } return $roles; } and change it to function editable_roles( $roles ){ //don’t change anything if current user is admin if (current_user_can(‘administrator’)) { return; }else{ if( isset( $roles[‘administrator’] … Read more

Add Role inherits?

You must set to true for them to take affect. If you do not specify true they all default to NULL which in turn basically makes them false. So to create a roll that allows pages only: add_role(‘page_editor’, ‘Page Editor’, array( ‘read’ => true, ‘edit_others_pages’ => true, ‘edit_pages’ => true, ‘edit_published_pages’ => true, ‘delete_pages’ => … Read more

Can’t manage to make translate_user_role() work

I think your function nesting is slightly muddled; call ucfirst after translating, like so: esc_html( ucfirst( translate_user_role( $user->roles[0] ) ) ); My bad, completely skipped a beat there. You should instead be using: translate_user_role( $GLOBALS[‘wp_roles’]->role_names[ $user->roles[0] ] ); It’s unreliable to assume that all role display names are simply ucfirst( $role key ). If that … Read more

Get (echo) all role names assigned to user

I assume you need a foreach loop and echo each roles name separately. Here’s how to do it: global $wp_roles; $user_role = get_userdata($user->ID)->roles; // Check if there is any role for this user if( $user_role ) { foreach ( $user_role as $key => $role ) { echo $wp_roles->role_names[ $role ]; // Add a seperator except … Read more

Change the user role after x days

Here is an idea that you can implement. I think it will work just fine. Save the expiration time in user meta. Say the meta name is change_role. What you save in the meta is unix time. If you want to change them back in 14 days. Set the meta value to time() + 60 … Read more

How to display user role

Change: $user_roles = $current_user->roles; with $user = new WP_User( $user_id ); $user_roles = $user->roles; and the $user_id should e the actual user id who’s role you are trying to get. Update, Sorry i just read the author template part so try this: //first get the current author whos page you are viewing if(isset($_GET[‘author_name’])) $curauth = … Read more

How to get all users with Author role capabilities?

Here’s a way to collect roles with the publish_posts capability: $roles__in = []; foreach( wp_roles()->roles as $role_slug => $role ) { if( ! empty( $role[‘capabilities’][‘publish_posts’] ) ) $roles__in[] = $role_slug; } and then we can query users with these roles: if( $roles__in ) $users = get_users( [ ‘roles__in’ => $roles__in, ‘fields’ => ‘ids’ ] ); … Read more