restrict buddypress message compose by capability for blog

I only want users with a custom capability on blog 202 to be able to compose buddypress private messages.
What code do I wrap with....

if (current_user_can_for_blog( '202', 'custom_capability' )) {


  • Vaughan
    • Support/SLS MockingJay


    try this in bp-custom.php (if it doesn't exist create the file & place it in wp-content/plugins/ folder

    function remove_bp_send_private_message_button() {
        remove_action( 'bp_get_send_message_button', 'bp_send_private_message_button', 9, 2 );
    add_action( 'bp_init', 'remove_bp_send_private_message_button' );
    function my_bp_send_private_message_button() {
        if (current_user_can_for_blog( '202', 'custom_capability' )) {
            echo bp_get_send_message_button();
    add_action( 'bp_get_send_message_button', 'my_bp_send_private_message_button' );

    i haven't tested but i think should work.

  • Ash
    • WordPress Hacker

    Hello there

    I hope you are well today and thanks for asking the question.

    You can go to /wp-content/plugins/buddypress/bp-templates/bp-legacy/buddypress/members/single/messages/compose.php and wrap the whole form with the condition if that works. I could not find any filter for this though. Please check and let me know if it works.


  • Atlanta
    • Syntax Hero

    @Vaughan, thanks on the quick reply. When I paste the code in bp-custom and then go to my site and click on compose I get this error

    "The connection was reset

    The connection to the server was reset while the page was loading.

    The site could be temporarily unavailable or too busy. Try again in a few moments.
    If you are unable to load any pages, check your computer's network connection.
    If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web.

    I can click on all other buttons on the site. I am not sure what I copied wrong.

    Thanks @Ashok, it worked. I ended up using this suggestion.


    When I pasted

     if (current_user_can_for_blog( '202', 'custom_capability' )) {

    at the start of the code and then ended it with

    else {
    echo "You need to be a member to send  a message";

    It removed the compose ability (good) but the you need to be a member message did not display.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.