bbp_check_for_flood

Check for flooding.

Description

bbp_check_for_flood( (constant) $anonymous_data = false, (int) $author_id = 0 ); 

Check to make sure that a user is not making too many posts in a short amount of time.

Parameters (2)

0. $anonymous_data — Optional. (constant) => false
The anonymous data.
1. $author_id — Optional. (int)
Supply if it's a post by a logged in user. Do not supply if supplying $anonymous_data.

Usage

  1. if ( !function_exists( 'bbp_check_for_flood' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/common/functions.php'; 
  3.  
  4. // The anonymous data. 
  5. $anonymous_data = false; 
  6.  
  7. // Optional. Supply if it's a post by a logged in user. 
  8. // Do not supply if supplying $anonymous_data. 
  9. $author_id = -1; 
  10.  
  11. // NOTICE! Understand what this does before running. 
  12. $result = bbp_check_for_flood($anonymous_data, $author_id); 
  13.  

Defined (1)

The function is defined in the following location(s).

/includes/common/functions.php  
  1. function bbp_check_for_flood( $anonymous_data = false, $author_id = 0 ) { 
  2.  
  3. // Option disabled. No flood checks. 
  4. $throttle_time = get_option( '_bbp_throttle_time' ); 
  5. if ( empty( $throttle_time ) ) 
  6. return true; 
  7.  
  8. // User is anonymous, so check a transient based on the IP 
  9. if ( !empty( $anonymous_data ) && is_array( $anonymous_data ) ) { 
  10. $last_posted = get_transient( '_bbp_' . bbp_current_author_ip() . '_last_posted' ); 
  11.  
  12. if ( !empty( $last_posted ) && time() < $last_posted + $throttle_time ) { 
  13. return false; 
  14.  
  15. // User is logged in, so check their last posted time 
  16. } elseif ( !empty( $author_id ) ) { 
  17. $author_id = (int) $author_id; 
  18. $last_posted = bbp_get_user_last_posted( $author_id ); 
  19.  
  20. if ( isset( $last_posted ) && time() < $last_posted + $throttle_time && !current_user_can( 'throttle' ) ) { 
  21. return false; 
  22. } else { 
  23. return false; 
  24.  
  25. return true;