/** * Output the raw value of the last posted time. * * @since 2.1.0 bbPress (r3910) * * @param int $user_id User ID to retrieve value for * @uses bbp_get_user_last_posted() To output the last posted time */ function bbp_user_last_posted($user_id = 0) { echo bbp_get_user_last_posted($user_id); }
/** * Check for flooding * * Check to make sure that a user is not making too many posts in a short amount * of time. * * @since 2.0.0 bbPress (r2734) * * @param false|array $anonymous_data Optional - if it's an anonymous post. Do * not supply if supplying $author_id. * Should have key 'bbp_author_ip'. * Should be sanitized (see * {@link bbp_filter_anonymous_post_data()} * for sanitization) * @param int $author_id Optional. Supply if it's a post by a logged in user. * Do not supply if supplying $anonymous_data. * @uses get_option() To get the throttle time * @uses get_transient() To get the last posted transient of the ip * @uses bbp_get_user_last_posted() To get the last posted time of the user * @uses current_user_can() To check if the current user can throttle * @return bool True if there is no flooding, false if there is */ 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; }