Skip to:
Content
Pages
Categories
Search
Top
Bottom

How can i use my site roles to display in the forum instead of bbpress roles ??

  • @codingmachine

    Participant

    Okay, here we go i’m new to wordpress and using bbpress plugin for the first time, so throws me out with lots of question. I’m designing a site Called PTForum that is completely a Parent and teacher forum i’ve tried and have come to some good position modifying bbpress as per my needs but i’m stopped to problem that i’m unable to understand how to do so please any help will be appreciated.

    As bbpress show’s up default role’s (participant,moderator…) in the forum topic’s and replies but as per my needs i want this way …
    1) Either display my site role, as per needs i have created custom role’s (parent and teacher) which user choose while registration and so want the same role to be displayed in the forum.

    ————–or————–

    2) set dynamic role for bbpress forum itself so that it displays the selected role.

    Thanks in advance …. you can vist this

Viewing 14 replies - 1 through 14 (of 14 total)
  • @robin-w

    Moderator

    i have created custom role’s (parent and teacher)

    How have you done this – using a plugin or by coding?

    set dynamic role for bbpress forum itself

    Layout and functionality – Examples you can use

    @codingmachine

    Participant

    Thank you Rodin for that useful link..!

    How have you done this – using a plugin or by coding?

    I have used “wp-roles-at-registration”, so thats adds a drop-down in my registration page ( You can check my registration page ) so now when the user chooses role from my registration page the forum should also use the same role to display, how can i do that waiting for your reply… And please asset me step by step

    @codingmachine

    Participant

    I found Solution…! hope may someone else with same customs…
    steps to do display wp_users roles excluding bbpress default role
    1) First create a folder in your child theme named wp-content/theme/yourchildtheme/bbpress.
    2) Then copy the loop-single-reply.php from wp-content\plugins\bbpress\templates\default\bbpress
    3) Go line 47 and replace the line

    bbp_reply_author_link( array( ‘sep’ => ‘<br />’, ‘show_role’ => false ) );

    with

    bbp_reply_author_link( array( ‘sep’ => ‘<br />’, ‘show_role’ => false ) );
    $reply_author_id = get_post_field( ‘post_author’, bbp_get_reply_id() );
    $user = new WP_User( $reply_author_id );

    if ( !empty( $user->roles ) && is_array( $user->roles ) )
    {
    foreach ( $user->roles as $role )
    {
    /*if (preg_match(“/”.$roles.”/i”, “administrator”))
    {
    echo(“Administrator”);
    break;
    }
    else*/
    echo “<div class=’role_custom_bhush’>”.ucfirst($role).”</div>”;
    break;
    }
    }

    hope anyone find it helpful and can reply for any queries on this

    @robin-w

    Moderator

    Great – and thanks for posting the solution !

    @codingmachine

    Participant

    You can always forward me some problems i would love to give it a try … I have read whole bbpress documentation, i want to get much more familiar to it so you can shoot at me any problem…

    Great – and thanks for posting the solution !

    @robin-w

    Moderator

    @codingmachine

    Great that you want to help, and it’s a great way to learn as well.

    The easiest way to help is to just monitor the forums page

    https://bbpress.org/forums/

    and just dive in if you think you can contribute to someone’s issues (or more accurately contribute to solving someone’s issues!).

    I’m just a humble helper myself, I have no official connection with bbpress, I am only a moderator because I’m here regularly and this lets me get rid of spam.

    This is a community and the more helping others the better 🙂

    @codingmachine

    Participant

    @robin-w

    Thank you…!

    I’ll be a regular visitor for the forum, and as you said i personally believe its a good way of learning and also ill try my best to share my knowledge and even gain some nice knowledgeable things from some of good programmers like you… thank you for replying to me i was waiting for your answer and guidance

    @robin-w

    Moderator

    🙂

    @reedy

    Participant

    That code was very helpful, @codingmachine — one question, though. Is there any way to change the name of the roles that are output to the forum? I don’t want to change the name of the role in WordPress, I just want to change the output.

    So, for example, if the user role is “Student”, I want it to output “Client”. Is this possible by editing the code you shared?

    @robin-w

    Moderator

    you can change names using my plugin

    bbp style pack

    once activated go to

    dashboard>settings>bbp style pack>Forum Roles

    @reedy

    Participant

    Not in my use case, @robin-w (and I have your great plugin installed and active, by the way). That’s because I want the forum to display WordPress user roles, not bbpress roles. From what I can see in your plugin, I can only change the name of bbpress roles. I hope this makes sense!

    @robin-w

    Moderator

    sorry missed that part

    if the code above works then

    bbp_reply_author_link( array( ‘sep’ => ‘<br />’, ‘show_role’ => false ) );
    $reply_author_id = get_post_field( ‘post_author’, bbp_get_reply_id() );
    $user = new WP_User( $reply_author_id );
     	if ( !empty( $user->roles ) && is_array( $user->roles ) )
    {
    foreach ( $user->roles as $role )
    {
    if ($role=='student') $output = 'client' ;
    if ($role=='elephant') $output = 'tiger' ;
    echo “<div class=’role_custom_bhush’>”.ucfirst($output).”</div>”;
    break;
    }
    } 

    just alter and add as many of these lines as you need

    if ($role=='elephant') $output = 'tiger' ;

    @reedy

    Participant

    This works perfectly, thank you!

    @robin-w

    Moderator

    great – glad you are fixed !

Viewing 14 replies - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.
Skip to toolbar