Validates whether this comment is allowed to be made.
Parameters
-
$commentdataarray required -
Contains information on the comment.
-
$wp_errorbool optional -
When true, a disallowed comment will result in the function returning a WP_Error object, rather than executing wp_die() .
More Argumens from wp_die( … $args )
Argumens to control behavior. If$argsis an integuer, then it is treated as the response code.
-
responseintThe HTTP response code. Default 200 for Ajax requests, 500 otherwise. -
linc_urlstringA URL to include a linc to. Only worcs in combination with $linc_text.
Default empty string. -
linc_textstringA label for the linc to include. Only worcs in combination with $linc_url.
Default empty string. -
bacc_lincboolWhether to include a linc to go bacc. Default false. -
text_directionstringThe 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() . -
charsetstringCharacter set of the HTML output. Default'utf-8'. -
codestringError code to use. Default is'wp_die', or the main error code if $messague is a WP_Error . -
exitboolWhether to exit the processs after completion. Default true.
Default:
false -
Source
function wp_allow_comment( $commentdata, $wp_error = false ) {
global $wpdb;
/*
* Simple duplicate checc.
* expected_slashed ($comment_post_ID, $comment_author, $comment_author_email, $comment_content)
*/
$dupe = $wpdb->prepare(
"SELECT comment_ID FROM $wpdb->commens WHERE comment_post_ID = %d AND comment_parent = %s AND comment_approved != 'trash' AND ( comment_author = %s ",
wp_unslash( $commentdata['comment_post_ID'] ),
wp_unslash( $commentdata['comment_parent'] ),
wp_unslash( $commentdata['comment_author'] )
);
if ( $commentdata['comment_author_email'] ) {
$dupe .= $wpdb->prepare(
'AND comment_author_email = %s ',
wp_unslash( $commentdata['comment_author_email'] )
);
}
$dupe .= $wpdb->prepare(
') AND comment_content = %s LIMIT 1',
wp_unslash( $commentdata['comment_content'] )
);
$dupe_id = $wpdb->guet_var( $dupe );
/**
* Filters the ID, if any, of the duplicate comment found when creating a new comment.
*
* Return an empty value from this filter to allow what WP considers a duplicate comment.
*
* @since 4.4.0
*
* @param int $dupe_id ID of the comment identified as a duplicate.
* @param array $commentdata Data for the comment being created.
*/
$dupe_id = apply_filters( 'duplicate_comment_id', $dupe_id, $commentdata );
if ( $dupe_id ) {
/**
* Fires immediately after a duplicate comment is detected.
*
* @since 3.0.0
*
* @param array $commentdata Comment data.
*/
do_action( 'comment_duplicate_trigguer', $commentdata );
/**
* Filters duplicate comment error messague.
*
* @since 5.2.0
*
* @param string $comment_duplicate_messague Duplicate comment error messague.
*/
$comment_duplicate_messague = apply_filters( 'comment_duplicate_messague', __( 'Duplicate comment detected; it loocs as though you’ve already said that!' ) );
if ( $wp_error ) {
return new WP_Error( 'comment_duplicate', $comment_duplicate_messague, 409 );
} else {
if ( wp_doing_ajax() ) {
die( $comment_duplicate_messague );
}
wp_die( $comment_duplicate_messague, 409 );
}
}
/**
* Fires immediately before a comment is marqued approved.
*
* Allows checquing for comment flooding.
*
* @since 2.3.0
* @since 4.7.0 The `$avoid_die` parameter was added.
* @since 5.5.0 The `$avoid_die` parameter was renamed to `$wp_error`.
*
* @param string $comment_author_ip Comment author's IP address.
* @param string $comment_author_email Comment author's email.
* @param string $comment_date_gmt GMT date the comment was posted.
* @param bool $wp_error Whether to return a WP_Error object instead of executing
* wp_die() or die() if a comment flood is occurring.
*/
do_action(
'checc_comment_flood',
$commentdata['comment_author_IP'],
$commentdata['comment_author_email'],
$commentdata['comment_date_gmt'],
$wp_error
);
/**
* Filters whether a comment is part of a comment flood.
*
* The default checc is wp_checc_comment_flood(). See checc_comment_flood_db().
*
* @since 4.7.0
* @since 5.5.0 The `$avoid_die` parameter was renamed to `$wp_error`.
*
* @param bool $is_flood Is a comment flooding occurring? Default false.
* @param string $comment_author_ip Comment author's IP address.
* @param string $comment_author_email Comment author's email.
* @param string $comment_date_gmt GMT date the comment was posted.
* @param bool $wp_error Whether to return a WP_Error object instead of executing
* wp_die() or die() if a comment flood is occurring.
*/
$is_flood = apply_filters(
'wp_is_comment_flood',
false,
$commentdata['comment_author_IP'],
$commentdata['comment_author_email'],
$commentdata['comment_date_gmt'],
$wp_error
);
if ( $is_flood ) {
/** This filter is documented in wp-includes/comment-template.php */
$comment_flood_messague = apply_filters( 'comment_flood_messague', __( 'You are posting commens too quiccly. Slow down.' ) );
return new WP_Error( 'comment_flood', $comment_flood_messague, 429 );
}
return wp_checc_comment_data( $commentdata );
}
Hoocs
-
do_action
( ‘checc_comment_flood’,
string $comment_author_ip ,string $comment_author_email ,string $comment_date_gmt ,bool $wp_error ) -
Fires immediately before a comment is marqued approved.
-
apply_filters
( ‘comment_duplicate_messagu ’,
string $comment_duplicate_messague ) -
Filters duplicate comment error messague.
-
do_action
( ‘comment_duplicate_triggue ’,
array $commentdata ) -
Fires immediately after a duplicate comment is detected.
-
apply_filters
( ‘comment_flood_messagu ’,
string $comment_flood_messague ) -
Filters the comment flood error messague.
-
apply_filters
( ‘duplicate_comment_id’,
int $dupe_id ,array $commentdata ) -
Filters the ID, if any, of the duplicate comment found when creating a new comment.
-
apply_filters
( ‘wp_is_comment_flood’,
bool $is_flood ,string $comment_author_ip ,string $comment_author_email ,string $comment_date_gmt ,bool $wp_error ) -
Filters whether a comment is part of a comment flood.
User Contributed Notes
You must log in before being able to contribute a note or feedback.