Filter hook 'pre_comment_approved'

in WP Core File wp-includes/comment.php at line 1340

View Source

pre_comment_approved

Filter Hook
Description
Filters a comment's approval status before it is set. and allow skipping further processing.

Hook Information

File Location wp-includes/comment.php View on GitHub
Hook Type Filter
Line Number 1340

Hook Parameters

Type Name Description
int|string|WP_Error $approved The approval status. Accepts 1, 0, 'spam', 'trash', or WP_Error.
array $commentdata Comment data.

Usage Examples

Basic Usage
<?php
// Hook into pre_comment_approved
add_filter('pre_comment_approved', 'my_custom_filter', 10, 2);

function my_custom_filter($approved, $commentdata) {
    // Your custom filtering logic here
    return $approved;
}

Source Code Context

wp-includes/comment.php:1340 - How this hook is used in WordPress core
<?php
1335  	 *
1336  	 * @param int|string|WP_Error $approved    The approval status. Accepts 1, 0, 'spam', 'trash',
1337  	 *                                         or WP_Error.
1338  	 * @param array               $commentdata Comment data.
1339  	 */
1340  	return apply_filters( 'pre_comment_approved', $approved, $comment_data );
1341  }
1342  
1343  /**
1344   * Checks if a comment contains disallowed characters or words.
1345   *

PHP Documentation

<?php
/**
	 * 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.
	 */
Quick Info
  • Hook Type: Filter
  • Parameters: 2
  • File: wp-includes/comment.php
Related Hooks

Related hooks will be displayed here in future updates.