Title: pre_comment_approved
Published: April 25, 2014
Last modified: May 20, 2026

---

# apply_filters( ‘pre_comment_approved’, int|string|WP_Error $approved, array $commentdata )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/hooks/pre_comment_approved/?output_format=md#parameters)
 * [More Information](https://developer.wordpress.org/reference/hooks/pre_comment_approved/?output_format=md#more-information)
 * [Source](https://developer.wordpress.org/reference/hooks/pre_comment_approved/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/pre_comment_approved/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/pre_comment_approved/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/hooks/pre_comment_approved/?output_format=md#user-contributed-notes)

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

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

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

 `$approved`int|string|[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)

The approval status. Accepts 1, 0, `'spam'`, `'trash'`, or [WP_Error](https://developer.wordpress.org/reference/classes/wp_error/).

`$commentdata`array

Comment data.

## 󠀁[More Information](https://developer.wordpress.org/reference/hooks/pre_comment_approved/?output_format=md#more-information)󠁿

 * A filter hook called by the [wp_allow_comment()](https://developer.wordpress.org/reference/functions/wp_allow_comment/)
   function prior to inserting a comment into the database. The filter is applied
   to the proposed comment’s approval status, allowing a plugin to override.
 * [wp_allow_comment()](https://developer.wordpress.org/reference/functions/wp_allow_comment/)
   handles the preliminary approval checking, and that approval status is passed
   through this filter before it returns.
 * The `$commentdata` array contains the same indices as the array returned by [WP_Comment_Query::get_comments()](https://developer.wordpress.org/reference/classes/wp_comment_query/get_comments/),
   including:
    ` 'comment_post_ID' - The post to which the comment will apply 'comment_author'-(
   may be empty) 'comment_author_email' - (may be empty) 'comment_author_url' - (
   may be empty) 'comment_author_IP' - IP address 'comment_agent' - e.g., "Mozilla/
   5.0..." 'comment_content' - The text of the proposed comment 'comment_type' -'
   pingback', 'trackback', or empty for regular comments 'user_ID' - (empty if not
   logged in)
 * Return Values:
    ` 0 (int) comment is marked for moderation as "Pending" 1 (int)
   comment is marked for immediate publication as "Approved" 'spam' (string) comment
   is marked as "Spam" 'trash' (string) comment is to be put in the Trash  In all
   cases the comment is added to the database, even spam. Comments marked as spam
   will never be visible on the front end. Spam comments are kept for possible analysis
   by plugins.
 * Prior to WP 3.1, the filter was not passed $comment_data and instead was expected
   to use global variables such as _$comment\_ID_ to access information about the
   comment. (see: [https://core.trac.wordpress.org/ticket/14802](https://core.trac.wordpress.org/ticket/14802))

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

    ```php
    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/7.0/src/wp-includes/comment.php#L1349)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/comment.php#L1349-L1349)

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

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

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

  |

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

| Version | Description | 
| [4.9.0](https://developer.wordpress.org/reference/since/4.9.0/) | Returning a [WP_Error](https://developer.wordpress.org/reference/classes/wp_error/) value from the filter will short-circuit comment insertion and allow skipping further processing. | 
| [2.1.0](https://developer.wordpress.org/reference/since/2.1.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/hooks/pre_comment_approved/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/hooks/pre_comment_approved/?output_format=md#comment-content-4611)
 2.   [Steven Lin](https://profiles.wordpress.org/stevenlinx/)  [  5 years ago  ](https://developer.wordpress.org/reference/hooks/pre_comment_approved/#comment-4611)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpre_comment_approved%2F%23comment-4611)
    Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpre_comment_approved%2F%23comment-4611)
 4. Example migrated from Codex:
 5. The following code examines comment content and modifies approval status if needed
 6.     ```php
        <?php
        add_filter( 'pre_comment_approved' , 'filter_handler' , '99', 2 );
    
        function filter_handler( $approved , $commentdata )
        {
          // insert code here to inspect $commentdata and determine 'approval', 'disapproval', 'trash', or 'spam' status
    
          return $approved;
        }
        ?>
        ```
    
 7.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpre_comment_approved%2F%3Freplytocom%3D4611%23feedback-editor-4611)

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