BuddyDev

Search

Private Message Rate Limiter with role based code

  • Participant
    Level: Yogi
    Posts: 1117
    calu on #20891

    Hi Brajesh, i’m testing Private Message Rate Limiter with the code you supplied, but I can’t make it work.

    No matter the user role, subscriber or customer, the setting in BP Rate Limit Private Message is the one that apply.

    What should the message value be in BP settings to make the code work? I have tried with 0, but this gives unlimited messages to all roles. Setting the value to 5, restricts all roles, what is wrong?

    Regards
    Carsten

    function buddydev_custom_get_role_based_message_limit( $role ) {
    
    	// duration- in minutes
    	// limit - how many in that duration
    	$limits = array(
    		'administrator' => array(
    			'duration' => 1440,
    			'limit'    => 0, // 0 means no limit.
    		),
    		'editor'        => array(
    			'duration' => 60,
    			'limit'    => 10,
    		),
    		'author'        => array(
    			'duration' => 60,
    			'limit'    => 5,
    		),
    		'contributor'   => array(
    			'duration' => 1440,
    			'limit'    => 20,
    		),
    		'subscriber'    => array(
    			'duration' => 1440,
    			'limit'    =>  5,
    		),
    		'customer'    => array(
    			'duration' => 1440,
    			'limit'    => 0, // 0 means no limit.
    		),
    	);
    
    	$default = array(
    		'duration' => bp_get_option( 'bp_rate_limit_pm_throttle_duration', 5 ),
    		'limit'    => get_option( 'bp_rate_limit_pm_count', 5 ),
    	);
    
    	return isset( $limits[ $role ] ) ? $limits[ $role ] : $default;
    }
  • Keymaster
    (BuddyDev Team)
    Posts: 24636
    Brajesh Singh on #20892

    Hi Carsten,
    It seems to me you have not added the actual filter. Can you please post me the complete code.

    There should be a few more lines.

    Thank you
    Brajesh

  • Participant
    Level: Yogi
    Posts: 1117
    calu on #20895

    Hi Brajesh, I don’t recall, which topic this code is found, you did not add it to the code snippet library by any chance?

    Regards
    Carsten

  • Keymaster
    (BuddyDev Team)
    Posts: 24636
    Brajesh Singh on #20922

    Hi Carsten,
    I am sorry, It took me some time to find out the original code.

    I had shared it as a gist here
    https://gist.github.com/sbrajesh/cc37e8794527f86046e1d880490d974b

    Can you please check if you are using the complete code?

    Regards
    Brajesh

  • Participant
    Level: Yogi
    Posts: 1117
    calu on #20923

    Hi Brajesh, thanks for the code, you were right, my code wasn’t complete.

    The code is working now, but there is a bug some were.

    If I set the limit to 0, no limit, messaging is unblocked as it should. If I set the limit to 5000 within one minute, messaging is blocked.

    Are the BP Rate Limit Private Message dashboard settings overruled by the settings in the code?

    Regards
    Carsten

    'subscriber'    => array(
    			'duration' => 1,
    			'limit'    => 0,
    'subscriber'    => array(
    			'duration' => 1,
    			'limit'    => 5000,
  • Participant
    Level: Yogi
    Posts: 1117
    calu on #20924

    Should this be changed?

    $default = array(
    		'duration' => bp_get_option( 'bp_rate_limit_pm_throttle_duration', 5 ),
    		'limit'    => get_option( 'bp_rate_limit_pm_count', 5 ),
    	);
  • Keymaster
    (BuddyDev Team)
    Posts: 24636
    Brajesh Singh on #20925

    Hi Carsten,
    Can you please check from the Users screen which roles the user in question have?

  • Participant
    Level: Yogi
    Posts: 1117
    calu on #20926

    The user has subscriber role, I also changed the role to customer. Even with a limit of 30000, messages is blocked. It seems like all other values than 0, are blocked?

    'customer'    => array(
    			'duration' => 1440,
    			'limit'    => 0,
    		),
    'customer'    => array(
    			'duration' => 1440,
    			'limit'    => 30000,
    		),
  • Keymaster
    (BuddyDev Team)
    Posts: 24636
    Brajesh Singh on #20929

    Hi Carsten,
    Can you please confirm if you are using the latest version of the private message rate limiter plugin?

    I am not sure why it is not working for you as I do have it working.

    Also, is there any chance you are using our message privacy plugin or any other plugin that blocks receiving message from users?

    Regards
    BRajesh

  • Participant
    Level: Yogi
    Posts: 1117
    calu on #20932

    Hi Brajesh, I’m using Version 1.0.6, and I’m not using message privacy plugin, or other which can block the messages, to my knowledge.

    Now that I know the code is correct, I have to go through my setup, to find out what is conflicting with the code.
    Just to clarify, the BP Rate Limit Private Message settings in the dashboard are irrelevant?

    Regards
    Carsten

You must be logged in to reply to this topic.

This topic is: not resolved