Change WordPress user roles and capabilities › Forums › How to or FAQ › How do I change the bbp-role to display the name of the role?
- This topic has 7 replies, 2 voices, and was last updated 4 years, 11 months ago by demonboy.
-
AuthorPosts
-
11/10/2019 at 07:35 #6003demonboyParticipant
Hi,
Just installed the pro plugin. I have created new BBPress roles based on Participant. Each role has an ID and a name but in the forum all roles are just displaying as ‘member’. How do I get the forum to display the name I gave it in URE?
Cheers
12/10/2019 at 02:50 #6006VladimirKeymasterHi,
It may depend from a theme or additional plugins you use. Show screenshot to give me more information.
Mine test bbPress shows at forum only user name. It shows role at user profile after click on the user name and it’s a role name not ID: “Forum Role: Participant”.
12/10/2019 at 03:53 #6007demonboyParticipantHi Vladimir, thanks for getting back to me. Please see this Inspector page on the ‘member’ field of the forum:
12/10/2019 at 04:01 #6008VladimirKeymasterThanks for the information.
Does ‘x-bbp’ or ‘x-sidebar’ tell you something? Something related to a theme or plugin, which change bbPress default representation? We should look there in order to find place where it output author role as a Member.
Is ‘Member’ a primary role of this user?12/10/2019 at 06:55 #6009demonboyParticipantNo, ‘member’ isn’t a primary role, and yes the x-bbp is probably coming from my X theme. Thanks for the prompts – let me now go to the code developers and have a chat with them about this. I’ll get back to you when I’ve heard from them.
Thank you, Vladimir.
12/10/2019 at 07:00 #6010demonboyParticipantActually, one question: is there a general ID of the of those Participant roles I created? I may be able to get the theme developers to swap bbp-author-name with whatever was created by URE, bearing in mind I created six different participant roles.
14/10/2019 at 12:08 #6013VladimirKeymasterURE creates/edits user roles via WP API or directly in WP database.
Every role has 2 attributes: id and name in terms of URE’s user interface or in terms of WP API name (id) and display_name (name).
Look at the wp-includes/class-wp-roles.php:public function add_role( $role, $display_name, $capabilities = array() ) { if ( empty( $role ) || isset( $this->roles[ $role ] ) ) { return; } $this->roles[ $role ] = array( 'name' => $display_name, 'capabilities' => $capabilities, ); if ( $this->use_db ) { update_option( $this->role_key, $this->roles ); } $this->role_objects[ $role ] = new WP_Role( $role, $capabilities ); $this->role_names[ $role ] = $display_name; return $this->role_objects[ $role ]; }
WP_User object which you can get from wp_get_current_user() contains roles property, which contains the list (array) of roles (ID) granted to user.
20/10/2019 at 01:20 #6056demonboyParticipantI sussed this out, Vladimir. I added the standard bbpress participant user role to my functions file with the same name as the custom user role created in URE. Now bbpress picks up the correct user role. Thanks for your help!
-
AuthorPosts
- You must be logged in to reply to this topic.