Title: wp_check_comment_data
Published: November 13, 2024
Last modified: February 24, 2026

---

# wp_check_comment_data( array $comment_data ): int|string|󠀁[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)󠁿

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/wp_check_comment_data/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_check_comment_data/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_check_comment_data/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/wp_check_comment_data/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/wp_check_comment_data/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_check_comment_data/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_check_comment_data/?output_format=md#wp--skip-link--target)

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

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_check_comment_data/?output_format=md#parameters)󠁿

 `$comment_data`arrayrequired

Array of arguments for inserting a comment.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_check_comment_data/?output_format=md#return)󠁿

 int|string|[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)
The approval status on success (`0|1|'spam'|'trash'`), [WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)
otherwise.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_check_comment_data/?output_format=md#source)󠁿

    ```php
    function wp_check_comment_data( $comment_data ) {
    	global $wpdb;

    	if ( ! empty( $comment_data['user_id'] ) ) {
    		$user        = get_userdata( $comment_data['user_id'] );
    		$post_author = (int) $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 );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/comment.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/comment.php#L1291)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/comment.php#L1291-L1347)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/wp_check_comment_data/?output_format=md#hooks)󠁿

 [apply_filters( ‘pre_comment_approved’, int|string|WP_Error $approved, array $commentdata )](https://developer.wordpress.org/reference/hooks/pre_comment_approved/)

Filters a comment’s approval status before it is set.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_check_comment_data/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_check_comment_disallowed_list()](https://developer.wordpress.org/reference/functions/wp_check_comment_disallowed_list/)`wp-includes/comment.php` |

Checks if a comment contains disallowed characters or words.

  | 
| [check_comment()](https://developer.wordpress.org/reference/functions/check_comment/)`wp-includes/comment.php` |

Checks whether a comment passes internal checks to be allowed to add.

  | 
| [get_userdata()](https://developer.wordpress.org/reference/functions/get_userdata/)`wp-includes/pluggable.php` |

Retrieves user info by user ID.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  | 
| [wpdb::get_var()](https://developer.wordpress.org/reference/classes/wpdb/get_var/)`wp-includes/class-wpdb.php` |

Retrieves one value from the database.

  | 
| [wpdb::prepare()](https://developer.wordpress.org/reference/classes/wpdb/prepare/)`wp-includes/class-wpdb.php` |

Prepares a SQL query for safe execution.

  |

[Show 4 more](https://developer.wordpress.org/reference/functions/wp_check_comment_data/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_check_comment_data/?output_format=md#)

| Used by | Description | 
| [wp_new_comment()](https://developer.wordpress.org/reference/functions/wp_new_comment/)`wp-includes/comment.php` |

Adds a new comment to the database.

  | 
| [wp_allow_comment()](https://developer.wordpress.org/reference/functions/wp_allow_comment/)`wp-includes/comment.php` |

Validates whether this comment is allowed to be made.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_check_comment_data/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.7.0](https://developer.wordpress.org/reference/since/6.7.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_check_comment_data%2F)
before being able to contribute a note or feedback.