How to get the Role Name of the current user? (WordPress)

I’m not sure if bbPress follows WordPress conventions, but WP has a global class called $WP-roles that holds the role information. So, starting from what you have, there is the role of the current user: $current_role = $user->roles[1]; Next, retrieve a list of all roles: $all_roles = $wp_roles->roles; Then, loop through $all_roles and find the … Read more

get_userdata by username

get_userdata() function is an alias of get_user_by(‘ID’) function. Use this code: $username=”your user name”; $user = get_user_by(‘login’, $username); It will return WP_User object on success, or false on failure. See Codex. REST API: http://example.com/wp-json/wp/v2/users/<id>

Is there a simple way to manage capabilities per user?

You don’t necessarily have to assign roles to manage the user’s capabilities. First, register your custom post types with their respective capabilities. See capabilities under Function Reference/register post type – Parameters Managing User Capabilities You can use add_cap or remove_cap to add or remove user capabilities for a specific user. // Add capability to a … Read more

Gravity Forms Submit form as another user

A solution I have found is to manipulate the entry after submission using the following: function submit_as_user_proxy( $form ) { $id = null; $proxy_user_meta = null; $user_role=””; $field_existing_users = null; $field_signed_up_as = null; foreach ( $form[‘fields’] as &$field ) { if ( false !== strpos( $field->cssClass, ‘existing_users’ ) ) { $field_existing_users = &$field; } if … Read more

Admins can’t edit each other’s posts

Ok, I got it figured out. For some reason, current_user_can was returning false when an admin went to edit other user’s posts… I have no idea how admins lost the ability to do this, but putting this into functions.php is a workable bandaid that restores admin edit capabilities; $administrator = get_role(‘administrator’); $administrator->add_cap(‘edit_others_posts’);

User fields that can be edited by administrator?

I used this so a teacher would mark what courses the students were subscribed to. This is a generic version of that code, using only one extra field. Admin view Other users view <?php /* Plugin Name: Admin User Fields */ add_action( ‘admin_init’, ‘wpse_70265_init’); function wpse_70265_init() { if( current_user_can( ‘administrator’ ) ) { add_action( ‘show_user_profile’, … Read more

Completely hide user info

This is dependant on your theme/plugins so it’s impossible to answer, as s_ha_dum mentioned. For example some themes output the author name in the body as a class like <body class=”author-keanu”> or maybe they just use the author id like <body class=”archive author-22″> and then you can check the author by going to www.example.com/?author=22 and … Read more