wpseek.com
A WordPress-centric search engine for devs and theme authors



wp_check_comment_data › WordPress Function

Since6.7.0
Deprecatedn/a
wp_check_comment_data ( $comment_data )
Parameters:
  • (array) $comment_data Array of arguments for inserting a comment.
    Required: Yes
Returns:
  • (int|string|WP_Error) The approval status on success (0|1|'spam'|'trash'), WP_Error otherwise.
Defined at:
Codex:

Checks whether comment data passes internal checks or has disallowed content.



Source

function wp_check_comment_data( $comment_data ) {
	global $wpdb;

	if ( ! empty( $comment_data['user_id'] ) ) {
		$user        = get_userdata( $comment_data['user_id'] );
		$post_author = $wpdb->get_var(
			$wpdb->prepare(
				"SELECT post_author FROM $wpdb->posts WHERE ID = %d LIMIT 1",
				$comment_data['comment_post_ID']
			)
		);
	}

	if ( isset( $user ) && ( $comment_data['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_data['comment_author'],
			$comment_data['comment_author_email'],
			$comment_data['comment_author_url'],
			$comment_data['comment_content'],
			$comment_data['comment_author_IP'],
			$comment_data['comment_agent'],
			$comment_data['comment_type']
		) ) {
			$approved = 1;
		} else {
			$approved = 0;
		}

		if ( wp_check_comment_disallowed_list(
			$comment_data['comment_author'],
			$comment_data['comment_author_email'],
			$comment_data['comment_author_url'],
			$comment_data['comment_content'],
			$comment_data['comment_author_IP'],
			$comment_data['comment_agent']
		) ) {
			$approved = EMPTY_TRASH_DAYS ? 'trash' : 'spam';
		}
	}

	/**
	 * Filters a comment's approval status before it is set.
	 *
	 * @since 2.1.0
	 * @since 4.9.0 Returning a WP_Error value from the filter will short-circuit comment insertion
	 *              and allow skipping further processing.
	 *
	 * @param int|string|WP_Error $approved    The approval status. Accepts 1, 0, 'spam', 'trash',
	 *                                         or WP_Error.
	 * @param array               $commentdata Comment data.
	 */
	return apply_filters( 'pre_comment_approved', $approved, $comment_data );
}