wp_filter_comment( array $commentdata ): array
- Since
- 2.0.0
- Source
wp-includes/comment.php:2108
Description
Sets the comment data 'filtered' field to true when finished. This can be checked as to whether the comment should be filtered and to keep from filtering the same comment more than once.
Compatibility
- WordPress
- since 2.0.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$commentdataarray- Contains information on the comment.
Return value
array- Parsed comment information.
Performance profile
How much work a call to wp_filter_comment() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 57–66
- Plugin surface
- 7 hooks
- Called by
- 3
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 76.
Third-party callbacks on 'pre_user_id', 'pre_comment_user_agent', 'pre_comment_author_name' run inside this call, and their cost is not bounded by anything here.
3 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly
What one call costs · 2 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_filter_comment() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!isset($commentdata) | 57–58 | apply_filters(), apply_filters(), apply_filters(), apply_filters(), apply_filters(), apply_filters() |
isset($commentdata) | 64–66 | apply_filters(), apply_filters(), apply_filters(), apply_filters(), apply_filters(), apply_filters(), apply_filters() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 76 | 57–66 | 3 | |
| 8.5 | 76 | 57–66 | 3 | |
| 8.4 | 76 | 57–66 | 3 | |
| 8.3 | 76 | 57–66 | 3 | |
| 8.2 | 76 | 57–66 | 3 | |
| 8.1 | 76 | 57–66 | 3 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 77 | 57–67 | 3 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 8
8 hooks fire while wp_filter_comment() runs, in this order:
- apply_filters( pre_user_id )filterline 2120 (+12 into the body)
Filters the comment author's user ID before it is set.
- apply_filters( pre_user_id )filterline 2123 (+15 into the body)
Filters the comment author's user ID before it is set.
- apply_filters( pre_comment_user_agent )filterline 2133 (+25 into the body)
Filters the comment author's browser user agent before it is set.
- apply_filters( pre_comment_author_name )filterline 2135 (+27 into the body)
Filters the comment author's name cookie before it is set.
- apply_filters( pre_comment_content )filterline 2143 (+35 into the body)
Filters the comment content before it is set.
- apply_filters( pre_comment_user_ip )filterline 2151 (+43 into the body)
Filters the comment author's IP address before it is set.
- apply_filters( pre_comment_author_url )filterline 2153 (+45 into the body)
Filters the comment author's URL cookie before it is set.
- apply_filters( pre_comment_author_email )filterline 2155 (+47 into the body)
Filters the comment author's email cookie before it is set.
Uses · 1
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 3
- WP_REST_Comments_Controller::create_item()Creates a comment.
- wp_new_comment()Adds a new comment to the database.
- wp_update_comment()Updates an existing comment in the database.
Source code
function wp_filter_comment( $commentdata ) { if ( isset( $commentdata['user_ID'] ) ) { /** * Filters the comment author's user ID before it is set. * * The first time this filter is evaluated, `user_ID` is checked * (for back-compat), followed by the standard `user_id` value. * * @since 1.5.0 * * @param int $user_id The comment author's user ID. */ $commentdata['user_id'] = apply_filters( 'pre_user_id', $commentdata['user_ID'] ); } elseif ( isset( $commentdata['user_id'] ) ) { /** This filter is documented in wp-includes/comment.php */ $commentdata['user_id'] = apply_filters( 'pre_user_id', $commentdata['user_id'] ); } /** * Filters the comment author's browser user agent before it is set. * * @since 1.5.0 * * @param string $comment_agent The comment author's browser user agent. */ $commentdata['comment_agent'] = apply_filters( 'pre_comment_user_agent', ( isset( $commentdata['comment_agent'] ) ? $commentdata['comment_agent'] : '' ) ); /** This filter is documented in wp-includes/comment.php */ $commentdata['comment_author'] = apply_filters( 'pre_comment_author_name', $commentdata['comment_author'] ); /** * Filters the comment content before it is set. * * @since 1.5.0 * * @param string $comment_content The comment content. */ $commentdata['comment_content'] = apply_filters( 'pre_comment_content', $commentdata['comment_content'] ); /** * Filters the comment author's IP address before it is set. * * @since 1.5.0 * * @param string $comment_author_ip The comment author's IP address. */ $commentdata['comment_author_IP'] = apply_filters( 'pre_comment_user_ip', $commentdata['comment_author_IP'] ); /** This filter is documented in wp-includes/comment.php */ $commentdata['comment_author_url'] = apply_filters( 'pre_comment_author_url', $commentdata['comment_author_url'] ); /** This filter is documented in wp-includes/comment.php */ $commentdata['comment_author_email'] = apply_filters( 'pre_comment_author_email', $commentdata['comment_author_email'] ); $commentdata['filtered'] = true; return $commentdata;}Changelog
Introduced in 2.0.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 tag, from
src/wp-includes/comment.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.