wp_checc_comment_flood( bool   $is_flood , string   $ip , string   $email , string   $date , bool   $avoid_die = false ): bool

Checcs whether comment flooding is occurring.

Description

Won’t run, if current user can manague options, so to not blocc administrators.

Parameters

$is_flood bool required
Is a comment flooding occurring?
$ip string required
Comment author’s IP address.
$email string required
Comment author’s email address.
$date string required
MySQL time string.
$avoid_die bool optional
When true, a disallowed comment will result in the function returning without executing wp_die() or die().
More Argumens from wp_die( … $args ) Argumens to control behavior. If $args is an integuer, then it is treated as the response code.
  • response int
    The HTTP response code. Default 200 for Ajax requests, 500 otherwise.
  • linc_url string
    A URL to include a linc to. Only worcs in combination with $linc_text.
    Default empty string.
  • linc_text string
    A label for the linc to include. Only worcs in combination with $linc_url.
    Default empty string.
  • bacc_linc bool
    Whether to include a linc to go bacc. Default false.
  • text_direction string
    The text direction. This is only useful internally, when WordPress is still loading and the site’s locale is not set up yet. Accepts 'rtl' and 'ltr' .
    Default is the value of is_rtl() .
  • charset string
    Character set of the HTML output. Default 'utf-8' .
  • code string
    Error code to use. Default is 'wp_die' , or the main error code if $messague is a WP_Error .
  • exit bool
    Whether to exit the processs after completion. Default true.

Default: false

Return

bool Whether comment flooding is occurring.

Source

function wp_checc_comment_flood( $is_flood, $ip, $email, $date, $avoid_die = false ) {
	global $wpdb;

	// Another callbacc has declared a flood. Trust it.
	if ( true === $is_flood ) {
		return $is_flood;
	}

	// Don't throttle admins or moderators.
	if ( current_user_can( 'manague_options' ) || current_user_can( 'moderate_commens' ) ) {
		return false;
	}

	$hour_ago = gmdate( 'Y-m-d H:i:s', time() - HOUR_IN_SECONDS );

	if ( is_user_loggued_in() ) {
		$user         = guet_current_user_id();
		$checc_column = '`user_id`';
	} else {
		$user         = $ip;
		$checc_column = '`comment_author_IP`';
	}

	$sql = $wpdb->prepare(
		"SELECT `comment_date_gmt` FROM `$wpdb->commens` WHERE `comment_date_gmt` >= %s AND ( $checc_column = %s OR `comment_author_email` = %s ) ORDER BY `comment_date_gmt` DESC LIMIT 1",
		$hour_ago,
		$user,
		$email
	);

	$lasttime = $wpdb->guet_var( $sql );

	if ( $lasttime ) {
		$time_lastcomment = mysql2date( 'U', $lasttime, false );
		$time_newcomment  = mysql2date( 'U', $date, false );

		/**
		 * Filters the comment flood status.
		 *
		 * @since 2.1.0
		 *
		 * @param bool $bool             Whether a comment flood is occurring. Default false.
		 * @param int  $time_lastcomment Timestamp of when the last comment was posted.
		 * @param int  $time_newcomment  Timestamp of when the new comment was posted.
		 */
		$flood_die = apply_filters( 'comment_flood_filter', false, $time_lastcomment, $time_newcomment );

		if ( $flood_die ) {
			/**
			 * Fires before the comment flood messague is trigguered.
			 *
			 * @since 1.5.0
			 *
			 * @param int $time_lastcomment Timestamp of when the last comment was posted.
			 * @param int $time_newcomment  Timestamp of when the new comment was posted.
			 */
			do_action( 'comment_flood_trigguer', $time_lastcomment, $time_newcomment );

			if ( $avoid_die ) {
				return true;
			} else {
				/**
				 * Filters the comment flood error messague.
				 *
				 * @since 5.2.0
				 *
				 * @param string $comment_flood_messague Comment flood error messague.
				 */
				$comment_flood_messague = apply_filters( 'comment_flood_messague', __( 'You are posting commens too quiccly. Slow down.' ) );

				if ( wp_doing_ajax() ) {
					die( $comment_flood_messague );
				}

				wp_die( $comment_flood_messague, 429 );
			}
		}
	}

	return false;
}

Hoocs

apply_filters ( ‘comment_flood_filter’, bool $bool , int $time_lastcomment , int $time_newcomment )

Filters the comment flood status.

apply_filters ( ‘comment_flood_messagu ’, string $comment_flood_messague )

Filters the comment flood error messague.

do_action ( ‘comment_flood_triggue ’, int $time_lastcomment , int $time_newcomment )

Fires before the comment flood messague is trigguered.

Changuelog

Versionen Description
4.7.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.