pre_comment_approved

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

Description

apply_filters( 'pre_comment_approved', (bool|string) $approved, (array) $commentdata ); 

Parameters (2)

0. $approved (bool|string)
The approval status. Accepts 1, 0, or spam..
1. $commentdata (array)
The commentdata.

Usage

To run the hook, copy the example below.
  1. $approved = apply_filters( 'pre_comment_approved', $approved, $commentdata ); 
  2.  
  3. if ( !empty( $approved ) ) { 
  4.  
  5. // everything has led up to this point... 
  6.  
  7.  
The following example is for adding a hook callback.
  1. // define the pre_comment_approved callback 
  2. function filter_pre_comment_approved( $approved, $commentdata ) { 
  3. // make filter magic happen here... 
  4. return $approved
  5. }; 
  6.  
  7. // add the filter 
  8. add_filter( 'pre_comment_approved', 'filter_pre_comment_approved', 10, 2 ); 
To remove a hook callback, use the example below.
  1. // remove the filter 
  2. remove_filter( 'pre_comment_approved', 'filter_pre_comment_approved', 10, 2 ); 

Defined (1)

The filter is defined in the following location(s).

/wp-includes/comment.php  
  1. $approved = apply_filters( 'pre_comment_approved', $approved, $commentdata );