Skip to:
Content
Pages
Categories
Search
Top
Bottom

PM button in posts


  • shpitzyl
    Participant

    @shpitzyl

    I’m not sure if I should post this question here or in the buddypress forum.
    Is there any way to make a PM button in forum posts (using buddypress private messaging)?

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

  • Stephen Edgar
    Moderator

    @netweb

    I’m quite sure this is possible… Yes, done ;)

    A quickly whipped up plugin https://gist.github.com/ntwb/9887310

    
    function ntwb_bbp_bp_pm() {
        if(function_exists('bp_send_private_message_link') && is_user_logged_in() ) {
        	?>
        	<a href="<?php bp_send_private_message_link() ?>" title="Private Message">Private Message</a>
        	<?php
        }
    }
    add_action( 'bbp_theme_after_reply_author_details', 'ntwb_bbp_bp_pm' );
    

    Magic-Komplex
    Participant

    @magic-komplex

    I’d like to use this as well, but not sure how to implement this. Should this be in an own file (named how?) and added to my childtheme’s subolder bbpress, or should I place the code somewhere in an existing file?


    Stephen Edgar
    Moderator

    @netweb

    Should this be in an own file (named how?) and added to my childtheme’s subolder bbpress, or should I place the code somewhere in an existing file?

    Any of these methods will work ;)

    That said I’d download the gist from https://gist.github.com/ntwb/9887310 and extract the file and upload it as a plugin for your site.

    It needs a bit more work in that it shouldn’t be displayed for the current user or anonymous users.

    When I get a chance I’ll update that gist with those updates.


    shpitzyl
    Participant

    @shpitzyl

    Thanks.


    Magic-Komplex
    Participant

    @magic-komplex

    Thanks as well :-)


    Magic-Komplex
    Participant

    @magic-komplex

    @Stephen Edgar

    I’m updating this post, as you wished me to. I don’t know if it’s really related to your plugin above, at least it didn’t work for me. There’s no pm button in forum posts, but at the member profiles it doesn’t really show as well, only sometimes. As I already said in the other post, it seems to be quite moody and I have no idea why.
    Should i better open a thread in buddypress support forum? Anyway, here’s the link to my community, but you have to be logged in to view anything:

    thespiritualpath

    You should be seeing something like this:


    Magic-Komplex
    Participant

    @magic-komplex

    I’m sorry, but I don’t. :-( That’s what it looks like on my site:

    Do you have BuddyPress and the messaging component activated?

    Also depending on how you have modified your templates you need to make sure that your loop-single-reply.php template has the bbp_theme_after_reply_author_details hook still in place.


    Magic-Komplex
    Participant

    @magic-komplex

    Checked both, Buddypress messaging component is activated, and the loop-single-reply.php still contains the function bbp_theme_after_reply_author_details if that is what you meant:

    `<?php do_action( ‘bbp_theme_after_reply_author_details’ ); ?>

    </div><!– .bbp-reply-author –>`


    shpitzyl
    Participant

    @shpitzyl

    Hey Stephen, I’ve modified your code. With your code, when clicking on the link, it redirects the user to the compose form with the “Send To” field empty. I wanted to fill this field for the user automatically, just the way it works in buddypress user page. So I came up with this code.

    function ntwb_bbp_bp_pm() {
        if(function_exists('bp_send_private_message_link') && is_user_logged_in() ) {
    
            $user = get_userdata( bbp_get_reply_author_id()  ); 
    
            if ( !empty( $user->user_nicename ) ) {
                $user_nicename = $user->user_nicename;
            }
            $compose = bp_loggedin_user_domain() . bp_get_messages_slug() . '/compose/?r=' . $user_nicename;
            
            ?>
            <a>" title="Private Message">Private Message</a>
            <?php
        }
    }
    add_action( 'bbp_theme_after_reply_author_details', 'ntwb_bbp_bp_pm' );

    I’m not a php programmer and I’m not sure that I did it the right way, but hey, it works.

    @shpitzyl Thanks for sharing your code, now I need to come up with a way to keep and organize all these snippets of code…


    varma
    Participant

    @evildon

    @shpitzyl

    The final code seems to be not working. Still getting the blank username in the compose window.
    I think you need to have a href on the a tag there to work?

    If any one can solve this that would be great.

    Thanks


    shpitzyl
    Participant

    @shpitzyl

    @evildon, You’re right. not sure why I copied the code without that

    Here is the working code:

    function ntwb_bbp_bp_pm() {
        if(function_exists('bp_send_private_message_link') && is_user_logged_in() ) {
            global $bp;
            if ($bp->loggedin_user->id !== bbp_get_reply_author_id()){
              $user = get_userdata( bbp_get_reply_author_id()  ); 
    
              if ( !empty( $user->user_nicename ) ) {
                  $user_nicename = $user->user_nicename;
              }
              $compose = bp_loggedin_user_domain() . bp_get_messages_slug() . '/compose/?r=' . $user_nicename;
            
              ?>
              <div class="forum-pm"><a href="<?php echo $compose ?>" title="Private Message">Private Message</a></div>
              <?php
           }
        }
    }
    add_action( 'bbp_theme_after_reply_author_details', 'ntwb_bbp_bp_pm' );

    varma
    Participant

    @evildon

    @shpitzyl
    Superb, that worked out pretty well :)

    Thanks

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

You must be logged in to reply to this topic.