Shape the future of Social networking with WordPress: Join Project Midnight Sun! The next generation platform for community building with WordPress!

BuddyDev

Search

Are you using the BP Private Message Rate Limiter plugin to limit the number of private messages a user can send on a BuddyPress site during a given duration. If yes, then this guide will help you to  set different limits on the messages for different user roles.

Rate Limit The Number of Private Messages:-


add_filter( 'bp_rate_limit_pm_count', 'devb_custom_private_message_limit_count', 10, 2 );
function devb_custom_private_message_limit_count( $count, $user_id ) {

if( ! $user_id )
$user_id = get_current_user_id ();

if( user_can( $user_id, 'create_users' ) ) //admin
$count = 10;
elseif( user_can( $user_id, 'moderate_comments' ) )
$count = 8; //for editors
elseif( user_can( $user_id, 'edit_published_posts' ) )
$count = 6; //for authors
elseif( user_can( $user_id, 'edit_posts' ) )
$count = 6; //for Contributors
elseif( user_can( $user_id, 'read' ) )
$count = 6; //for Subscriber

return $count;
}

 

You can put the above code in bp-custom.php

Changing the allowed duration for different user types

add_filter( 'bp_rate_limit_pm_throttle_duration', 'devb_custom_private_message_throttle_duration', 10, 2 );

function devb_custom_private_message_throttle_duration( $duration, $user_id ) {

if( ! $user_id )
$user_id = get_current_user_id ();

if( user_can( $user_id, 'create_users' ) ) //admin
$duration = 2;// how many mins
elseif( user_can( $user_id, 'moderate_comments' ) )
$duration = 4; //for editors
elseif( user_can( $user_id, 'edit_published_posts' ) )
$duration = 6; //for authors
elseif( user_can( $user_id, 'edit_posts' ) )
$duration = 8; //for Contributors
elseif( user_can( $user_id, 'read' ) )
$duration = 10; //for Subscriber

return $duration;

}

 

You can use the above code to set different limits for different User types based on the WordPress user roles.