Skip to:
Content
Pages
Categories
Search
Top
Bottom

add custom link under author link in replies


  • andrew55
    Participant

    @andrew55

    I have a custom wp role that I have displaying under each user author link in all replies. There are different custom roles depending on the user. I was able to use it by implementing this snippet (inserted on loop-single-reply.php):

    <?php
    $user = new WP_User( bbp_get_reply_author_id() );
    echo $user->roles[0];
    ?>

    My question is how to get some text (with link) to show if a user has a specific custom role. For example, is user has “Graduate” role, I need a link with text to show under the role, in all the replies for all users.

    I’m not coder by any means, but I realize it will probably take a php “if” statement. Any suggestions on how I might accomplish this? Thanks for any help.

Viewing 5 replies - 1 through 5 (of 5 total)

  • kachan64
    Participant

    @kachan64

    There is a code I implemented a while ago on my site by doing something like this

    <?php 
    		$displayed_user = bbp_get_reply_author_id() ;
    		$role = bbp_get_user_role( $displayed_user);
    		if ( bbp_is_user_keymaster($displayed_user) ||$role == 'bbp_keymaster') : ?>
    		<div class="bbp-author-role">Administrator</div>
    <?php endif; ?>

    Where is says $role == ‘bbp_keymaster’ you can change that. If I get your question correctly.


    andrew55
    Participant

    @andrew55

    kachan64 – thank you. That is a good start. My main issue at this point seems to be that roles I’m using aren’t bbpress roles, so how I need to pull them is different. I will keep working at it.


    andrew55
    Participant

    @andrew55

    This is the best I’ve come up with so far, but it’s not working yet. Seems like this should work properly. It’s still getting printing the link in profile area in the replies:

    <?php
    $reply_user_id = bbp_get_reply_author_id();
    global $wp_roles;
    $reply_user = new WP_User( $reply_user_id );
    $roles = $reply_user->roles;
    $role = array_shift($roles);
    if ($user_role == 'graduate') {
    echo "<a href='http://www.mysite.com/page2/'>Graduate Link</a>";
    }
    ?>

    Thanks for any suggestions on how to get it right.


    andrew55
    Participant

    @andrew55

    This also seems like it should work to me:

    <?php
    $user = new WP_User( bbp_get_reply_author_id() );
    if  ($role == 'Graduate' ){
    echo "<a href='http://www.mysite.com/page2/'>Graduate Link</a>";
    }
    ?>

    But it’s still not showing link in replies for uses who have “graduate” role. Any suggestions?


    andrew55
    Participant

    @andrew55

    Got it! This seems to work:

    <?php
    $reply_user_id = bbp_get_reply_author_id();
    global $wp_roles;
    $reply_user = new WP_User( $reply_user_id );
    $roles = $reply_user->roles;
    $role = array_shift($roles);
    if  ($role == 'graduate' ){
    echo "<a href='http://www.mysite.com/page2/'>Graduate</a>";
    }
    ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Skip to toolbar