Skip to:
Content
Pages
Categories
Search
Top
Bottom

PM button in posts

  • @shpitzyl

    Participant

    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 16 replies - 1 through 16 (of 16 total)
  • @netweb

    Keymaster

    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

    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?

    @netweb

    Keymaster

    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

    Thanks.

    @magic-komplex

    Participant

    Thanks as well ๐Ÿ™‚

    @magic-komplex

    Participant

    @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

    @netweb

    Keymaster

    You should be seeing something like this:

    @magic-komplex

    Participant

    I’m sorry, but I don’t. ๐Ÿ™ That’s what it looks like on my site:

    @netweb

    Keymaster

    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

    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

    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.

    @netweb

    Keymaster

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

    @evildon

    Participant

    @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

    @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' );

    @evildon

    Participant

    @shpitzyl
    Superb, that worked out pretty well ๐Ÿ™‚

    Thanks

    @alriknijdam

    Participant

    Got an error when the user no longer exists.
    Edited your code, this one doesn’t give an error and hides the PM link:

    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' );

    Thank you very much for your code shpitzyl.

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