bbp_check_for_flood( false|array $anonymous_data = false, int $author_id )

Check for flooding

Description

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

Parameters

$anonymous_data

(false|array) (Optional) - if it's an anonymous post. Do not supply if supplying $author_id. Should have key 'bbp_author_ip'. Should be sanitized (see bbp_filter_anonymous_post_data() for sanitization)

Default value: false

$author_id

(int) (Optional) Supply if it's a post by a logged in user. Do not supply if supplying $anonymous_data.

Return

(bool) True if there is no flooding, false if there is

Source

File: bp-forums/common/functions.php

function bbp_check_for_flood( $anonymous_data = false, $author_id = 0 ) {

	// Option disabled. No flood checks.
	$throttle_time = get_option( '_bbp_throttle_time' );
	if ( empty( $throttle_time ) )
		return true;

	// User is anonymous, so check a transient based on the IP
	if ( !empty( $anonymous_data ) && is_array( $anonymous_data ) ) {
		$last_posted = get_transient( '_bbp_' . bbp_current_author_ip() . '_last_posted' );

		if ( !empty( $last_posted ) && time() < $last_posted + $throttle_time ) {
			return false;
		}

	// User is logged in, so check their last posted time
	} elseif ( !empty( $author_id ) ) {
		$author_id   = (int) $author_id;
		$last_posted = bbp_get_user_last_posted( $author_id );

		if ( isset( $last_posted ) && time() < $last_posted + $throttle_time && !current_user_can( 'throttle' ) ) {
			return false;
		}
	} else {
		return false;
	}

	return true;
}

Changelog

Changelog
Version Description
bbPress (r2734) Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.