Advertisements

wp_allow_comment

Definition:
function wp_allow_comment($commentdata) {}

Validates whether this comment is allowed to be made.

Parameters

  • array $commentdata: Contains information on the comment

Return values

returns:Signifies the approval status (0|1|’spam’)

Defined filters

  • pre_comment_approved
    apply_filters( 'pre_comment_approved', $approved, $commentdata )

Defined actions

  • comment_duplicate_trigger
    do_action( 'comment_duplicate_trigger', $commentdata );
  • check_comment_flood
    do_action( 'check_comment_flood', $comment_author_IP, $comment_author_email, $comment_date_gmt );

Source code

function wp_allow_comment($commentdata) {

	global $wpdb;

	extract($commentdata, EXTR_SKIP);



	// Simple duplicate check

	// expected_slashed ($comment_post_ID, $comment_author, $comment_author_email, $comment_content)

	$dupe = "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = '$comment_post_ID' AND comment_approved != 'trash' AND ( comment_author = '$comment_author' ";

	if ( $comment_author_email )

		$dupe .= "OR comment_author_email = '$comment_author_email' ";

	$dupe .= ") AND comment_content = '$comment_content' LIMIT 1";

	if ( $wpdb->get_var($dupe) ) {

		do_action( 'comment_duplicate_trigger', $commentdata );

		if ( defined('DOING_AJAX') )

			die( __('Duplicate comment detected; it looks as though you’ve already said that!') );



		wp_die( __('Duplicate comment detected; it looks as though you’ve already said that!') );

	}



	do_action( 'check_comment_flood', $comment_author_IP, $comment_author_email, $comment_date_gmt );



	if ( isset($user_id) && $user_id) {

		$userdata = get_userdata($user_id);

		$user = new WP_User($user_id);

		$post_author = $wpdb->get_var($wpdb->prepare("SELECT post_author FROM $wpdb->posts WHERE ID = %d LIMIT 1", $comment_post_ID));

	}



	if ( isset($userdata) && ( $user_id == $post_author || $user->has_cap('moderate_comments') ) ) {

		// The author and the admins get respect.

		$approved = 1;

	 } else {

		// Everyone else's comments will be checked.

		if ( check_comment($comment_author, $comment_author_email, $comment_author_url, $comment_content, $comment_author_IP, $comment_agent, $comment_type) )

			$approved = 1;

		else

			$approved = 0;

		if ( wp_blacklist_check($comment_author, $comment_author_email, $comment_author_url, $comment_content, $comment_author_IP, $comment_agent) )

			$approved = 'spam';

	}



	$approved = apply_filters( 'pre_comment_approved', $approved, $commentdata );

	return $approved;

}

3423

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: