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
Hi, Is it possible to add a “private message” button in the members’s directory page.
I have found this
but it is not working when I put it in the “bp-custom.php” file.
Any other ideas?
Thank you.
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
Hi,
I would out the Private Message Button in a WordPress Page that I use as Dashboard for the members of my website.
I would be able to create a Shortcode to Add the “Private Message” Button to the make to make any member able to send me a Private Message directly to me (only to me from the Dashboard).
1 – The first problem that I have is that I don’t know how to make the button to make eveyrbody able to contact me.
2 – I would use it like a shortcode to insert it everywhere it is necessary.
Please, how can I do it?
I really need support to do it.
Kind regards
G. Aloe
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?
1) If is text of private message too long, do read more
2) Seen date – please do date with time (date & time reading)
3) Why is there SSS? Please change text on “Mark as read” and “Mark as unread” It confuses people
4) When someone wants to see the messages in the conversation, please do that he will automatically jump down the page on the last message. Look how it works on Facebook, it also jumps down and you do not have to scroll down in order to write the answer.
5) Load more button – In some of the conversations I have more than 30 messages, then it’s confusing. Load newest button – Could you indicate a new incoming message as in the activities?
6) New messages at the top, old messages down. Similar as is the case activity. Reply form at the top as well.
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.
Thank you @danbp, this work ! I’m pretty sure this will help a lot (and not only me).
I’am asking something more : can this be adapt to allow only some user role to use private message ? (and not only some users ?) As the second part of the code you wrote, it remove the button to susbscriber.
(I’m learning PHP, I’ve tried to change the code but did not succeed to have it work…)
Hi,
try this (goes to bp-custom.php)
function bpex_remove_private_message_button( $button ) {
$user = bp_loggedin_user_id();
if ( $user == '4' || $user == '7' || $user == '25' ) { // the allowed user ID's
return $button;
}
if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
if ( $role == 'subscriber') {
$button = '';
}
}
}
add_filter( 'bp_get_send_message_button', 'bpex_remove_private_message_button', 1 , 1 );
No idea how to get specifically a pmpro defined user ID – you have to check their doc to adjust the above snippet. Note that it works on a standart install – without pmpro.
Hi @koded1999,
please, use the <code>
button to insert snippets. Also avoid double posting.
Closing this topic as duplicate.
Conversation goes ahead here:
Disable or Hide Private Message Button
@henrywright i managed to fix that and is working perfectly.
but i have another problem.
i will like to populate the subject automatically when user click the private message button from post
pls how can i achieve this.
thank you
@henrywright Please i will like to add private message button in post side bar. i used the code below it works but doesnt populate the author automatically. how can i fix this thanks in advance.
function bpfr_message_shortcode() {
$author = get_the_author();
$message = 'Login to contact advertiser!';
if( is_user_logged_in() ) {
return '<a>MESSAGE ADVERTISER</a>';
} else {
return $message;
}
}
add_shortcode( 'ksam', 'bpfr_message_shortcode' );
I have this very specific problem I need to solve. The thing is I have this BuddyPress-Setup that is linked to my WP and WC Vendors. What I’m trying to achive is a sidebar/seller info tab displaying the BuddyPress-Profil informations from the Vendor. Something like this when the User is logged in:
- Profile name (BuddyPress/WP)
- Storename (from WC Vendors)
- phone number
- email-address
- Button to send Private Message to Seller
If the User is not logged in there should be a Button with the meassgae to please login. I already know how to do that button.
I already linked my BuddyPress Profile with the WC Vendors store. So that the “Visit-Store”-Button is displayed on the BuddyPress profile of my Users (from knowledge Base of WC Vendors)
How is the best way to approche this problem?
I’m not looking for a fullywritten out solution just some suggestions where to start.
I’m running the current versions of WP, BuddyPress, WooCommerce and WC Vendors(free) with the Socialize Theme. Also posted the question on the WC Vendors Support Site.
Thank you for your help.
Hi,
you can try to remove the private message button from the template or hide it with CSS.
And add a custom one who leads to admin inbox.
The link should look like
http://your-site.com/members/YOU/messages/compose/?r=THE ADMIN&_wpnonce=an_alpha_numeric_value
See here how you may code this
Codex and Forum are your friends to search about template customization.
You’re welcome. 😉
In case of, here’s another trick.
hi @fencer04,
thank for sharing your work. Well done, but it needs some revision (sorry).
At his activation on 2 test sites (one with 4.5.3/bp 2.6.1, other 4.6/bp2.6.2) i got a notice.
Array to string conversion in buddypress/bp-core/classes/class-bp-core-nav.php on line 279
from
sbpp04_privacy_check( ) ..\plugin.php:525
sbpp04_privacy_redirect( ) ..\buddypress-profile-privacy.php:176
bp_core_remove_nav_item( ) ..\buddypress-profile-privacy.php:184
BP_Core_Nav->delete_nav( ) ..\bp-core-buddybar.php:798
Another point concerning UI/UX is the Private button appearing on buddybar.
On this tab, a default message says Friends Only.
USERNAME has chosen to limit profile access to friends only.
That’s wrong! Because this appear on each profile, even if the owner hasn’t setup anything about his profile privacy.
So far i understand its fonctionality, this plugin let each member decide to show or not his whole profile page to friends or members only or to everyone (bp default).
– imo this tab should show “This profile is private” to anybody who is concerned by a privacy setting and should not appear at all if “Everyone” is set.
– the original BP Add as friend button on profile header or members directory is still there. This means that there is no need to go on Private tab to ask forfriendship.
This is a little confusing !
If the plugin is to extend profile settings, it should appear in profile settings only. And as it doesn’t superseed BP, there is no real reason to give him an extra tab on buddybar outside of the settings scope. A template notice could be enough to tell visitors what’s going on on such a profile.
Just my 2 cents.
Try this:
function mohammad_remove_private_message_button( $button ) {
$user_id = bp_loggedin_user_id();
if ( $user_id == '37' ) // the user ID
$button = '';
return $button;
}
add_filter( 'bp_get_send_message_button', 'mohammad_remove_private_message_button', 1 , 1 );
More details here:
[Resolved] how hide tab only for user? not remove/disable
Hi,
I have the BuddyPress 2.6.1.1 and Buddyblock from Philopress v1.6. I wanted to remove the private message and block button on the members directory so that I would only see the Add Friend button.
I’ve seen this on the template <?php do_action( 'bp_directory_members_actions' ); ?>
However, it does remove all of the actions. I only need the Add Friend Button to appear on the members directory can anyone help me please?
Thank you.
I tested your code and got first a page not found error while trying to send a private message from the new position.
I deactivated both action hook in cover and home files.
Disallowed cover image option. And tested again and everithing worked.
Allowed cover image and worked also.
So i confirm that your code works and all buttons show up (with active href’s), at least with Twenty Sixteen theme, at the members profile page bottom.
In resume, the only thing you have to do is to deactivate the original action hook in both files (so you can allow/disallow cover images).
Forgot to mention that there is a litle error in your code line 133
<?= wpautop(xprofile_get_field_data("About me", bp_displayed_user_id() ) ); ?>
Should be
<?php wpautop(xprofile_get_field_data("About me", bp_displayed_user_id() ) ); ?>
I made some changes on BuddyPress theme and now private and public message buttons appears when current user saw his Friends tab.
I removed this line: do_action( 'bp_member_header_actions' );
from cover-image-header.php file and now the messages buttons appears in user current Friend’s tab, with no href value.
Re private message button, try:
function masoud_remove_private_message_button( $button ) {
if ( ! is_super_admin() )
$button = '';
return $button;
}
add_filter( 'bp_get_send_message_button', 'masoud_remove_private_message_button', 1 , 1 );