DLParticipant
@prashantvatsh Thanks, I didn’t realize that every user could see the /members page and then if they click to a members profile they see the public and private messaging buttons too.
It seems that every new registration on the site automatically becomes a Buddypress member. So then they can see the membership list and message any other user without being a member of any group.
This isn’t good, easy for manual spammers to register and send PM spam to members.
Hello,
Currently clicking the “message” button to send a private message to another user takes me to Inbox and I have to click on the “Compose” tab (Note: the text “Inbox” says active!) and remember the username that I want to sent the message to.
https://prnt.sc/kuccn7
https://prnt.sc/kucd2g
SHOULD BE: Click on direct message takes me directly to compose with user name filled in.
My theme creator said this gets fixed by updating to BuddyPress 3.2, however I did and the problem persists.
Thank you for your help.
Im building a Apartment rental site.
And on the single apartment page I have a “Send a private message” button where people can send a private message to the person who owns the apartment and ask a questions.
So therefor I need to automaticly add the Apartment name in the Subject of the message.
Is it possible to make the subject within the URL something link “https://domain.com/members/user1/messages/compose/?r=user2?subject=xxxxxxxx” So the Subject is automaticly filled when people clicks the “Send a private message”
anyone? this is on buddypress profiles.. all plugins are deactivated so nothing is interfering as far as I know. When the “Private Message” Button is clicked it does not open the compose message with the user name in the title.. I think it might be a bug?
Hello I think I have a bug here, ok I am on buddypress Version 3.1.0 and logged in as admin I click on a member in the members directory and it has a button for “private message”, when clicked on I am assuming it is supposed to open the compose message box with the members name in the send to field but it is not doing that for some reason. I am assuming this also because of the url link. https://www.theexample.com/members/admin/messages/compose?r=thememberid
So is this a bug and how can I fix this if it is?
Hi Venutis! Thank you for the tip 🙂
But I found this code online created by a fellower named Brajesh Singh that worked very well. I just pasted it into my child theme’s functions.php
//////////////////////////////////////////////////////////////////
// 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' );
Hello,
I am new to Buddypress and this is my first post, I am new to web development also, and my PhP coding is not all that great, my years as a software developer was strictly in a windows environment (vb.net and sql)
I developed my own website and I am using Buddypress as part of my social media for users to connect with each other.
I have spent endless hours researching a fix, and I have not been able to find anything php file that I can edit in File Manager to edit or remove the line of code.
When a user updates an Activity, it updates in three places:
1. The Activity Stream (which is what I want)
2. The Member’s Profile where the Activity tab was (now removed, which is what I want)
3. Under the Member’s profile cover, with that pesky “view link” (which I DO NOT want to show)
And the “view link” is a bit buggy also, sometimes when a user clicks on it, it throws a 404 error, sometimes it opens up a blank page, and sometimes it opens up the recent activity that they posted in the Activity Stream.
Also in the members directory I have a button to send the user a private message whether or not they are friends.
When I click on a user name from the member’s directory, it take me to the compose a message like it is suppose to do, and the user name appears , but it does not save the user name in the send to box, do you have a fix for this also?
Thank you very much, a fix to these problems are greatly appreciated.
Naomi
@louisarthur – Thanks for sending me credentials. I’ve logged into your site to have a look.
As you note in your email, there’s no href attribute on these links. It’s not clear to me how this would be the case, but I can give you a starting point for looking into it yourself. Briefly, the buttons will be built without an href if the button constructing function passes an empty link_href parameter to the BP_Button class. The functions used in the two cases are different:
Message public: https://buddypress.trac.wordpress.org/browser/tags/2.9.2/src/bp-activity/bp-activity-template.php?marks=3090#L3079
Message privé: https://buddypress.trac.wordpress.org/browser/tags/2.9.2/src/bp-messages/bp-messages-template.php?marks=1362#L1360
The logic in each case is different, but since neither is showing up, I’m guessing that one of two things is happening:
1. One of the conditional checks shared between them is failing for some reason: bp_is_my_profile(), is_user_logged_in().
2. Something on your installation – perhaps your theme but probably a plugin (since you said Twenty Seventeen was exhibiting the problem as well) – is filtering both ‘bp_get_send_private_message_link’ and ‘bp_get_send_public_message_link’, and then incorrect returning empty strings.
To test idea #2, you might try – if you can – searching through your codebase for those filter names.
Hi,
I am trying to make the below two changes but tried all different solutions available on this form non worked.
1) Make the friend tab only visible to the account owner / logged-in user.
2) only friends can use and see the send private message button.
Can someone guide me to getting this accomplished. Most of the privacy settings I was able to integrate through plugins.
Okey, here is the correct code, thanks to @brajesh
// Adding message button in members directory
function filter_message_button_link( $link ) {
$link = wp_nonce_url( bp_loggedin_user_domain() . bp_get_messages_slug() . '/compose/?r='. bp_core_get_username( bp_get_member_user_id() ) );
return $link;
}
function display_private_message_button() {
if( is_user_logged_in() && bp_get_member_user_id() != bp_loggedin_user_id() ) {
//bp_send_message_button();
?>
<div id="send-private-message" class="generic-button">
<div class="private-message-button generic-button" ><a href="<?php echo filter_message_button_link(); ?>" class="button small secondary radius" rel="add"><i class="icon-envelope"></i></a></div>
</div>
<?php
add_filter('bp_get_send_private_message_link', 'filter_message_button_link', 1, 1 );
}
}
add_action( 'bp_directory_members_item_last', 'display_private_message_button',9999 );
I am trying to build a contact form that I can load on any page that would send a private message to a user. I already have the selected user/s in an array and now I would like to take that plus form data to (I’m guessing) message_new_message
Sample HTML Form
<form>
<label>Subject</label>
<input id="subjec_input" name="subject_input" type="text">
<label>Message Body</label>
<textarea id="body_input" name="body_input"></textarea>
<button id="submit_btn" name="submit_btn">Submit</button>
</form>
How I think arguments are given to the function
`messages_new_message( $args = array( ‘recipients’ => $user_id, ‘subject’ => $title, ‘content’ => $message );
Any help would be appreciated. Thanks
Help me with the code.
I need the Message button visible only to logged in users (Just like the Add Friend button works).
Check the code, please.
// Adding message button in members loop
function filter_message_button_link( $link ) {
$link = wp_nonce_url( bp_loggedin_user_domain() . bp_get_messages_slug() . '/compose/?r='. bp_core_get_username( bp_get_member_user_id() ) );
return $link;
}
function display_private_message_button() {
if( bp_get_member_user_id() != bp_loggedin_user_id() ) {
//bp_send_message_button();
?>
<div id="send-private-message" class="generic-button">
<div class="private-message-button generic-button" ><a href="<?php echo filter_message_button_link(); ?>" class="button small secondary radius" rel="add"><i class="icon-envelope"></i></a></div>
</div>
<?php
add_filter('bp_get_send_private_message_link', 'filter_message_button_link', 1, 1 );
}
}
add_action( 'bp_directory_members_item_last', 'display_private_message_button',9999 );
@modemlooper
@sbrajesh
@mercime
Hi
@r-a-y
@shanebp
I have this code (example img. LINK),
But, bp_loggedin_user_id() not work.
The Button is visible for all. Like Add Friend Button [ + ] the Message button needs to be visible only for Logged in users.
function filter_message_button_link( $link ) {
$link = wp_nonce_url( bp_loggedin_user_domain() . bp_get_messages_slug() . '/compose/?r='. bp_core_get_username( bp_get_member_user_id() ) );
return $link;
}
function display_private_message_button() {
if( bp_get_member_user_id() != bp_loggedin_user_id() ) {
//bp_send_message_button();
?>
<div id="send-private-message" class="generic-button">
<div class="private-message-button generic-button" ><a href="<?php echo filter_message_button_link(); ?>" class="button small secondary radius" rel="add"><i class="icon-envelope"></i></a></div>
</div>
<?php
add_filter('bp_get_send_private_message_link', 'filter_message_button_link', 1, 1 );
}
}
add_action( 'bp_directory_members_item_last', 'display_private_message_button',9999 );
Hello,
I’m trying to add a button so nonregistered users can contact register users from the profile page via private message.
Saw this discussion here:
https://buddypress.org/support/search/private+message+button/
But nothing worked for me. My website is not in English, should it be a problem? It looks like it bp-custom.php is not recognized, tried inserting the codes to function.php as well. Nothing works…
I’d be happy for some help here.
Tnx
Hello,i want to add an “star with me” button next to the button”private message””public message””add friend”buttons in member’s profile.now the chat plugin provider has told the Api to star the chat box ,it is a The JS function:
FlyzooApi.startChat(LocalUserId, SuccessCallback(), FailCallback()) .
i searched a lot about it but it is too hard for me to solve this question,now i wish to get help.
first of all, i’m new to the plugin and wordpress and i am building a website with community features. feel free to tell me about some cool plugins that hook into buddypress to add functionality (i already know about bbpress).
_____________________________________________________
on the wordpress dashboard in settings, buddypress, components, there is an unchecked feature named “site tracking”. what is this exactly and what does it do?
i am using the buddypress login widget. the only tabs it has are the user name and the logout button. is there a way to add more tabs to this like friends, private messages, forum topics (when bbpress is installed), etc?
in the options menu i can enable/disable users uploading profile picture and cover picture. is there an option to limit whether they upload a photo to the site or use a url to post the photo? can i make it so that i can select stock images for user to choose their profile picture and cover picture from?
i notice there is also support for additional community interaction like grouping and posting on group pages. is there a way for users to have their own personal mini blogs that can be viewed by other users?
how would i go about customizing the design/layout of user profiles?
any other advice for me?
Hi all,
I’m using the latest version of BuddyPress & found a bug in the private message modul.
When I write a new message to a member and forget the subject line there is an error message to fill out the subject line –> that’s correct.
But after fill out the subject line and send on the “send” Button, there is another error message, that the username is not correct! –> that’s the bug. When I fill out the subject line and the body-text in one step, the message can be send without any problems.
Is this a general bug in BuddyPress?
Best regards
Miriam
http://www.familyship.org
do you remember that in the user profile appear as buttons to write private or public messages?
I would like to add more buttons (and I did it – I do not remember which files have changed…) but I wish these buttons are only visible in your profile and not at all (thus the reverse of what happens to the buttons of the listed messages above). How can I do? thank you
Thank you so much for this code! I’ve spent several hours trying to use other people’s code to hide the button and even tried to make my own but nothing worked until I found your code. I just switched it around because I only wanted one particular group to not be able to send messages while the rest can.
Posting in case someone in the future needs the opposite of your code:
add_filter( 'bp_get_send_message_button', function( $array ) {
if ( pmpro_hasMembershipLevel('NAMEOFPMPLEVEL') ) {
return '';
} else {
return $array;
}
} );
Also, I am looking for the same code as you to restrict non-paying users from sending private messages. I found a code that looks promising but unfortunately doesn’t work. It sees if the user is logged in and if not redirects them. Then if the person is logged in it checks their role but if they’re not that role they’re supposed to be redirected. But it just breaks my whole site. Any ideas?
function my_function() {
if ( ! is_user_logged_in() && bp_is_current_component( 'messages' ) ) {
// Current user is not logged in so don't let them see stuff. In this case, private messages
wp_redirect( home_url() );
exit;
}
$flag = false;
// Get current user info.
$user = wp_get_current_user();
if ( ! in_array( 'student', $user->roles ) ) {
// The current member is not a student.
$flag = true;
}
if ( $flag && bp_is_current_component( 'messages' ) ) {
The currently logged-in member is not a student and is trying to view private messaging. Let's redirect them away.
wp_redirect( home_url() );
exit;
}
}
add_action( 'init', 'my_function' );
This works and hides the button, but I’m curious. Can someone still send a private message to another user when they are “not” friends using URL manipulation or should the _wpnonce stop that?
hi @masoud1111,
all i found was how to hide that button, or remove it.
but not show it only on some profiles
You just need to add some conditionnals.
Try this (in bp-custom.php) and give feed back if it works.
function bpex_private_message_button( $button ) {
$user = bp_loggedin_user_id();
if ( is_super_admin() ) {
return $button;
}
if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
if ( $role == 'subscriber' || $role == 'contributor' || $role == 'author' || $role == 'editor' ) {
// hide button for these roles
$button = '';
}
}
// allow the button to appear on admin's profile only
if ( bp_is_active( 'xprofile' ) && bp_is_user() ) {
$user_id = bp_displayed_user_id();
// assuming admin's ID is 1
if ( $user_id == 1 ) {
return $button;
}
}
}
add_filter( 'bp_get_send_message_button', 'bpex_private_message_button', 1 , 1 );
The function is working correctly on my install.
Perhaps you have an issue with quotes, ie after copy/pasting the snippet from a topic where the code whas inserted without using the code button.
Which software do you use to publish bp-custom ?
Copy/paste following and give a try:
function buddydev_hide_members_directory_from_all_except_admin() {
if ( bp_is_members_directory() && ! is_super_admin() ) {
//should we add a message too?
//bp_core_add_message( 'Private page.', 'error' );
bp_core_redirect( site_url('/') );
}
}
add_action( 'bp_template_redirect', 'buddydev_hide_members_directory_from_all_except_admin' );
This topic is titled “Function to hide private message depending of user role”.
and the snippet does that ! Subscribers have no access to the button. So far i remember it is also the default role in WordPress. You change that to your need.
The first condition in the snippet allows some users (by ID) to access the button, whatever their role.
If you want to add other WP roles, you simply copy the 2nd conditionnal if(role=='') and add another role if(role=='mamamouchi") { //do something }.
Or you use only the user ID if you have only a few members allowed to access. I litle understanding of php is of course a + to do that.
You have the basics in the snippet. Now, it’s to you now to make it work for your need.