Notifications
Clear all

Create "message user" button on non-wpforo page.

5 Posts
3 Users
0 Likes
1,785 Views
Posts: 3
Customer
Topic starter
(@taskemann)
Member
Joined: 6 years ago

Hello.

I'm developing a global scrap trading marketplace where users will have the ability to create marketplace listings. The site also has a community where I run wpForo + wpForo Private Messages. I previously ran buddyPress, but decided to switch to wpForo since buddyPress loaded an incredible amount of resources.

I was wondering if you guys could help me with a hook for functions.php to allow me to create a "message user" link/button on a non-wpforo marketplace page so users can send messages directly to other members via wpForo Private Messages without having them to leave the other user's marketplace listing to look them up at the forum to send messages?

 

Thanks & best regards,

 

Jimmy

 

4 Replies
Astghik
Posts: 5872
Admin
(@astgh)
Illustrious Member
Joined: 6 years ago

Hi Jimmy,

You can find the privet message function, that can be useful for you in  wp-content\plugins\wpforo-private-messages\wpforopm.php  the function is add_message_button.  

Reply
Posts: 3
Customer
Topic starter
(@taskemann)
Member
Joined: 6 years ago

Thanks! I will check it out.

 

Jimmy

Reply
Posts: 3
Customer
Topic starter
(@taskemann)
Member
Joined: 6 years ago

I can't get any hook I try to create to work.

When I used buddypress, I got a hook + shortcode made that worked very well that displayed different text on the message button if the user was logged in or not, or if the marketplace listing had the visitor’s ID as author. Perhaps it’s possible to replace/implement some of the code above to into it to make it function?

My old buddypress private message hook + shortcode on non-plugin page:

//////////////////////////////////////////////////////////////////
// BuddyPress send private message button
//////////////////////////////////////////////////////////////////

/**
* Get a link to send PM to the given User.
*
* @param int $user_id user id.
*
* @return string
*/
function buddydev_get_send_private_message_to_user_url( $user_id ) {
return wp_nonce_url( bp_loggedin_user_domain() . bp_get_messages_slug() . '/compose/?r=' . bp_core_get_username( $user_id ) );
}

/**
* Shortcode [bp-pm-button username=optional_some_user_name]
*
* @param array $atts shortcode attributes.
* @param string $content content.
*
* @return string
*/
function buddydev_private_message_button_shortcode( $atts, $content = '' ) {
// User is not logged in.
if ( ! is_user_logged_in() ) {
return '';
}

$atts = shortcode_atts( array(
'user_id' => '',
'username' => '',
'label' => 'Send Private Message',
), $atts );

$user_id = absint( $atts['user_id'] );
$user_login = $atts['username'];

// if the username is given, override the user id.
if ( $user_login ) {
$user = get_user_by( 'login', $user_login );
if ( ! $user ) {
return '';
}
$user_id = $user->ID;
}

if ( ! $user_id ) {
if ( ! in_the_loop() ) {
return '';
}

$user_id = get_the_author_meta('ID' );
}
// do not show the PM button for the user, if it is aimed at them.
if ( bp_loggedin_user_id() === $user_id ) {
return '';
}

// if we are here, generate the button.
$button = sprintf('<a href="%1$s">%2$s</a>', buddydev_get_send_private_message_to_user_url( $user_id ), $atts['label'] );

return $button . $content;
}

add_shortcode( 'bp-pm-button', 'buddydev_private_message_button_shortcode' );
Reply
Posts: 20
(@power505)
Eminent Member
Joined: 5 years ago

@taskemann did you manage to do it?

Reply
Share:
Scroll to top