wp_update_comment( array $commentarr, bool $wp_error = false ): int|false|WP_Error
- Since
- 2.0.0, 4.9.0, 5.5.0, 5.5.0
- Source
wp-includes/comment.php:2869
Description
Filters the comment and makes sure certain fields are valid before updating.
Compatibility
- WordPress
- since 5.5.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
$commentarrarray- Contains information on the comment.
$wp_errorbooloptional- Whether to return a WP_Error on failure. Default false.Default:
false
Return value
int|false|WP_Error- The value 1 if the comment was updated, 0 if not updated.
False or a WP_Error object on failure.
Performance profile
How much work a call to wp_update_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
- Heavy
- Scaling
- Scales with input
- Instructions
- 15–150
- Plugin surface
- 3 hooks
- Called by
- 3
Reaches the database via ->update().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 199.
Third-party callbacks on 'comment_save_pre', 'wp_update_comment_data', 'edit_comment' 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
- querycontent query
get_post()called directly - hookthird-party callbacks
apply_filters()called directly - sqldatabase query
->update()called directly - cacheobject cache
wp_cache_delete_multiple()one call below wp_update_comment()
Further down the call graph this can also reach serialize, option and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 68 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_update_comment() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
empty($comment) | 15 | get_comment() |
empty($comment) | 22 | get_comment(), __() |
!empty($comment) && !empty($commentarr) && !get_post() | 23 | get_comment(), get_post() |
!empty($comment) && !empty($commentarr) && !get_post() | 30 | get_comment(), get_post(), __() |
!empty($comment) && empty($commentarr) && has_filter() && $value && is_wp_error() | 76–81 | get_comment(), has_filter(), wp_slash(), array_merge(), wp_filter_comment(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error() |
!empty($comment) && empty($commentarr) && has_filter() && is_wp_error() | 80–85 | get_comment(), has_filter(), wp_slash(), array_merge(), wp_filter_comment(), remove_filter(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error() |
!empty($comment) && empty($commentarr) && has_filter() && is_wp_error() | 80–85 | get_comment(), has_filter(), add_filter(), wp_slash(), array_merge(), wp_filter_comment(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error() |
!empty($comment) && !empty($commentarr) && get_post() && has_filter() && $value && is_wp_error() | 82–87 | get_comment(), get_post(), has_filter(), wp_slash(), array_merge(), wp_filter_comment(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error() |
!empty($comment) && empty($commentarr) && !has_filter() && $value && is_wp_error() | 83–89 | get_comment(), has_filter(), user_can(), wp_slash(), array_merge(), wp_filter_comment(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error() |
!empty($comment) && empty($commentarr) && has_filter() && !$value && is_wp_error() | 84–89 | get_comment(), has_filter(), add_filter(), wp_slash(), array_merge(), wp_filter_comment(), remove_filter(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error() |
!empty($comment) && !empty($commentarr) && get_post() && has_filter() && is_wp_error() | 86–91 | get_comment(), get_post(), has_filter(), wp_slash(), array_merge(), wp_filter_comment(), remove_filter(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error() |
!empty($comment) && !empty($commentarr) && get_post() && has_filter() && is_wp_error() | 86–91 | get_comment(), get_post(), has_filter(), add_filter(), wp_slash(), array_merge(), wp_filter_comment(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error() |
56 further outcomes, up to 150 instructions
!empty($comment) && empty($commentarr) && !has_filter() && is_wp_error() | 87–93 | get_comment(), has_filter(), user_can(), wp_slash(), array_merge(), wp_filter_comment(), remove_filter(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error() |
!empty($comment) && empty($commentarr) && !has_filter() && is_wp_error() | 87–93 | get_comment(), has_filter(), user_can(), add_filter(), wp_slash(), array_merge(), wp_filter_comment(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error() |
!empty($comment) && !empty($commentarr) && get_post() && !has_filter() && $value && is_wp_error() | 89–95 | get_comment(), get_post(), has_filter(), user_can(), wp_slash(), array_merge(), wp_filter_comment(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error() |
!empty($comment) && !empty($commentarr) && get_post() && has_filter() && !$value && is_wp_error() | 90–95 | get_comment(), get_post(), has_filter(), add_filter(), wp_slash(), array_merge(), wp_filter_comment(), remove_filter(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error() |
!empty($comment) && empty($commentarr) && !has_filter() && !$value && is_wp_error() | 91–97 | get_comment(), has_filter(), user_can(), add_filter(), wp_slash(), array_merge(), wp_filter_comment(), remove_filter(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error() |
!empty($comment) && empty($commentarr) && has_filter() && $value && !is_wp_error() && $result === false | 93–98 | get_comment(), has_filter(), wp_slash(), array_merge(), wp_filter_comment(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID() |
!empty($comment) && !empty($commentarr) && get_post() && !has_filter() && is_wp_error() | 93–99 | get_comment(), get_post(), has_filter(), user_can(), wp_slash(), array_merge(), wp_filter_comment(), remove_filter(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error() |
!empty($comment) && !empty($commentarr) && get_post() && !has_filter() && is_wp_error() | 93–99 | get_comment(), get_post(), has_filter(), user_can(), add_filter(), wp_slash(), array_merge(), wp_filter_comment(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error() |
!empty($comment) && empty($commentarr) && has_filter() && !is_wp_error() && $result === false | 97–102 | get_comment(), has_filter(), wp_slash(), array_merge(), wp_filter_comment(), remove_filter(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID() |
!empty($comment) && empty($commentarr) && has_filter() && !is_wp_error() && $result === false | 97–102 | get_comment(), has_filter(), add_filter(), wp_slash(), array_merge(), wp_filter_comment(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID() |
!empty($comment) && !empty($commentarr) && get_post() && !has_filter() && !$value && is_wp_error() | 97–103 | get_comment(), get_post(), has_filter(), user_can(), add_filter(), wp_slash(), array_merge(), wp_filter_comment(), remove_filter(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error() |
!empty($comment) && !empty($commentarr) && get_post() && has_filter() && $value && !is_wp_error() && $result === false | 99–104 | get_comment(), get_post(), has_filter(), wp_slash(), array_merge(), wp_filter_comment(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID() |
!empty($comment) && empty($commentarr) && !has_filter() && $value && !is_wp_error() && $result === false | 100–106 | get_comment(), has_filter(), user_can(), wp_slash(), array_merge(), wp_filter_comment(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID() |
!empty($comment) && empty($commentarr) && has_filter() && !$value && !is_wp_error() && $result === false | 101–106 | get_comment(), has_filter(), add_filter(), wp_slash(), array_merge(), wp_filter_comment(), remove_filter(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID() |
!empty($comment) && empty($commentarr) && has_filter() && $value && !is_wp_error() && $result === false | 103–108 | get_comment(), has_filter(), wp_slash(), array_merge(), wp_filter_comment(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID(), __(), ->update() |
!empty($comment) && !empty($commentarr) && get_post() && has_filter() && !is_wp_error() && $result === false | 103–108 | get_comment(), get_post(), has_filter(), wp_slash(), array_merge(), wp_filter_comment(), remove_filter(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID() |
!empty($comment) && !empty($commentarr) && get_post() && has_filter() && !is_wp_error() && $result === false | 103–108 | get_comment(), get_post(), has_filter(), add_filter(), wp_slash(), array_merge(), wp_filter_comment(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID() |
!empty($comment) && empty($commentarr) && !has_filter() && !is_wp_error() && $result === false | 104–110 | get_comment(), has_filter(), user_can(), wp_slash(), array_merge(), wp_filter_comment(), remove_filter(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID() |
!empty($comment) && empty($commentarr) && !has_filter() && !is_wp_error() && $result === false | 104–110 | get_comment(), has_filter(), user_can(), add_filter(), wp_slash(), array_merge(), wp_filter_comment(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID() |
!empty($comment) && !empty($commentarr) && get_post() && !has_filter() && $value && !is_wp_error() && $result === false | 106–112 | get_comment(), get_post(), has_filter(), user_can(), wp_slash(), array_merge(), wp_filter_comment(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID() |
!empty($comment) && empty($commentarr) && has_filter() && !is_wp_error() && $result === false | 107–112 | get_comment(), has_filter(), wp_slash(), array_merge(), wp_filter_comment(), remove_filter(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID(), __(), ->update() |
!empty($comment) && empty($commentarr) && has_filter() && !is_wp_error() && $result === false | 107–112 | get_comment(), has_filter(), add_filter(), wp_slash(), array_merge(), wp_filter_comment(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID(), __(), ->update() |
!empty($comment) && !empty($commentarr) && get_post() && has_filter() && !$value && !is_wp_error() && $result === false | 107–112 | get_comment(), get_post(), has_filter(), add_filter(), wp_slash(), array_merge(), wp_filter_comment(), remove_filter(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID() |
!empty($comment) && empty($commentarr) && !has_filter() && !$value && !is_wp_error() && $result === false | 108–114 | get_comment(), has_filter(), user_can(), add_filter(), wp_slash(), array_merge(), wp_filter_comment(), remove_filter(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID() |
!empty($comment) && !empty($commentarr) && get_post() && has_filter() && $value && !is_wp_error() && $result === false | 109–114 | get_comment(), get_post(), has_filter(), wp_slash(), array_merge(), wp_filter_comment(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID(), __(), ->update() |
!empty($comment) && empty($commentarr) && !has_filter() && $value && !is_wp_error() && $result === false | 110–116 | get_comment(), has_filter(), user_can(), wp_slash(), array_merge(), wp_filter_comment(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID(), __(), ->update() |
!empty($comment) && !empty($commentarr) && get_post() && !has_filter() && !is_wp_error() && $result === false | 110–116 | get_comment(), get_post(), has_filter(), user_can(), wp_slash(), array_merge(), wp_filter_comment(), remove_filter(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID() |
!empty($comment) && !empty($commentarr) && get_post() && !has_filter() && !is_wp_error() && $result === false | 110–116 | get_comment(), get_post(), has_filter(), user_can(), add_filter(), wp_slash(), array_merge(), wp_filter_comment(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID() |
!empty($comment) && empty($commentarr) && has_filter() && !$value && !is_wp_error() && $result === false | 111–116 | get_comment(), has_filter(), add_filter(), wp_slash(), array_merge(), wp_filter_comment(), remove_filter(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID(), __(), ->update() |
!empty($comment) && !empty($commentarr) && get_post() && has_filter() && !is_wp_error() && $result === false | 113–118 | get_comment(), get_post(), has_filter(), wp_slash(), array_merge(), wp_filter_comment(), remove_filter(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID(), __(), ->update() |
!empty($comment) && !empty($commentarr) && get_post() && has_filter() && !is_wp_error() && $result === false | 113–118 | get_comment(), get_post(), has_filter(), add_filter(), wp_slash(), array_merge(), wp_filter_comment(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID(), __(), ->update() |
!empty($comment) && empty($commentarr) && !has_filter() && !is_wp_error() && $result === false | 114–120 | get_comment(), has_filter(), user_can(), wp_slash(), array_merge(), wp_filter_comment(), remove_filter(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID(), __(), ->update() |
!empty($comment) && empty($commentarr) && !has_filter() && !is_wp_error() && $result === false | 114–120 | get_comment(), has_filter(), user_can(), add_filter(), wp_slash(), array_merge(), wp_filter_comment(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID(), __(), ->update() |
!empty($comment) && !empty($commentarr) && get_post() && !has_filter() && !$value && !is_wp_error() && $result === false | 114–120 | get_comment(), get_post(), has_filter(), user_can(), add_filter(), wp_slash(), array_merge(), wp_filter_comment(), remove_filter(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID() |
!empty($comment) && !empty($commentarr) && get_post() && !has_filter() && $value && !is_wp_error() && $result === false | 116–122 | get_comment(), get_post(), has_filter(), user_can(), wp_slash(), array_merge(), wp_filter_comment(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID(), __(), ->update() |
!empty($comment) && empty($commentarr) && has_filter() && $value && !is_wp_error() && $result !== false | 116–128 | get_comment(), has_filter(), wp_slash(), array_merge(), wp_filter_comment(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID(), clean_comment_cache(), wp_update_comment_count(), do_action(), get_comment(), wp_transition_comment_status() |
!empty($comment) && !empty($commentarr) && get_post() && has_filter() && !$value && !is_wp_error() && $result === false | 117–122 | get_comment(), get_post(), has_filter(), add_filter(), wp_slash(), array_merge(), wp_filter_comment(), remove_filter(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID(), __(), ->update() |
!empty($comment) && empty($commentarr) && !has_filter() && !$value && !is_wp_error() && $result === false | 118–124 | get_comment(), has_filter(), user_can(), add_filter(), wp_slash(), array_merge(), wp_filter_comment(), remove_filter(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID(), __(), ->update() |
!empty($comment) && !empty($commentarr) && get_post() && !has_filter() && !is_wp_error() && $result === false | 120–126 | get_comment(), get_post(), has_filter(), user_can(), wp_slash(), array_merge(), wp_filter_comment(), remove_filter(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID(), __(), ->update() |
!empty($comment) && !empty($commentarr) && get_post() && !has_filter() && !is_wp_error() && $result === false | 120–126 | get_comment(), get_post(), has_filter(), user_can(), add_filter(), wp_slash(), array_merge(), wp_filter_comment(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID(), __(), ->update() |
!empty($comment) && empty($commentarr) && has_filter() && !is_wp_error() && $result !== false | 120–132 | get_comment(), has_filter(), wp_slash(), array_merge(), wp_filter_comment(), remove_filter(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID(), clean_comment_cache(), wp_update_comment_count(), do_action(), get_comment(), wp_transition_comment_status() |
!empty($comment) && empty($commentarr) && has_filter() && !is_wp_error() && $result !== false | 120–132 | get_comment(), has_filter(), add_filter(), wp_slash(), array_merge(), wp_filter_comment(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID(), clean_comment_cache(), wp_update_comment_count(), do_action(), get_comment(), wp_transition_comment_status() |
!empty($comment) && !empty($commentarr) && get_post() && has_filter() && $value && !is_wp_error() && $result !== false | 122–134 | get_comment(), get_post(), has_filter(), wp_slash(), array_merge(), wp_filter_comment(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID(), clean_comment_cache(), wp_update_comment_count(), do_action(), get_comment(), wp_transition_comment_status() |
!empty($comment) && empty($commentarr) && !has_filter() && $value && !is_wp_error() && $result !== false | 123–136 | get_comment(), has_filter(), user_can(), wp_slash(), array_merge(), wp_filter_comment(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID(), clean_comment_cache(), wp_update_comment_count(), do_action(), get_comment(), wp_transition_comment_status() |
!empty($comment) && !empty($commentarr) && get_post() && !has_filter() && !$value && !is_wp_error() && $result === false | 124–130 | get_comment(), get_post(), has_filter(), user_can(), add_filter(), wp_slash(), array_merge(), wp_filter_comment(), remove_filter(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID(), __(), ->update() |
!empty($comment) && empty($commentarr) && has_filter() && !$value && !is_wp_error() && $result !== false | 124–136 | get_comment(), has_filter(), add_filter(), wp_slash(), array_merge(), wp_filter_comment(), remove_filter(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID(), clean_comment_cache(), wp_update_comment_count(), do_action(), get_comment(), wp_transition_comment_status() |
!empty($comment) && !empty($commentarr) && get_post() && has_filter() && !is_wp_error() && $result !== false | 126–138 | get_comment(), get_post(), has_filter(), wp_slash(), array_merge(), wp_filter_comment(), remove_filter(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID(), clean_comment_cache(), wp_update_comment_count(), do_action(), get_comment(), wp_transition_comment_status() |
!empty($comment) && !empty($commentarr) && get_post() && has_filter() && !is_wp_error() && $result !== false | 126–138 | get_comment(), get_post(), has_filter(), add_filter(), wp_slash(), array_merge(), wp_filter_comment(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID(), clean_comment_cache(), wp_update_comment_count(), do_action(), get_comment(), wp_transition_comment_status() |
!empty($comment) && empty($commentarr) && !has_filter() && !is_wp_error() && $result !== false | 127–140 | get_comment(), has_filter(), user_can(), wp_slash(), array_merge(), wp_filter_comment(), remove_filter(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID(), clean_comment_cache(), wp_update_comment_count(), do_action(), get_comment(), wp_transition_comment_status() |
!empty($comment) && empty($commentarr) && !has_filter() && !is_wp_error() && $result !== false | 127–140 | get_comment(), has_filter(), user_can(), add_filter(), wp_slash(), array_merge(), wp_filter_comment(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID(), clean_comment_cache(), wp_update_comment_count(), do_action(), get_comment(), wp_transition_comment_status() |
!empty($comment) && !empty($commentarr) && get_post() && !has_filter() && $value && !is_wp_error() && $result !== false | 129–142 | get_comment(), get_post(), has_filter(), user_can(), wp_slash(), array_merge(), wp_filter_comment(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID(), clean_comment_cache(), wp_update_comment_count(), do_action(), get_comment(), wp_transition_comment_status() |
!empty($comment) && !empty($commentarr) && get_post() && has_filter() && !$value && !is_wp_error() && $result !== false | 130–142 | get_comment(), get_post(), has_filter(), add_filter(), wp_slash(), array_merge(), wp_filter_comment(), remove_filter(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID(), clean_comment_cache(), wp_update_comment_count(), do_action(), get_comment(), wp_transition_comment_status() |
!empty($comment) && empty($commentarr) && !has_filter() && !$value && !is_wp_error() && $result !== false | 131–144 | get_comment(), has_filter(), user_can(), add_filter(), wp_slash(), array_merge(), wp_filter_comment(), remove_filter(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID(), clean_comment_cache(), wp_update_comment_count(), do_action(), get_comment(), wp_transition_comment_status() |
!empty($comment) && !empty($commentarr) && get_post() && !has_filter() && !is_wp_error() && $result !== false | 133–146 | get_comment(), get_post(), has_filter(), user_can(), wp_slash(), array_merge(), wp_filter_comment(), remove_filter(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID(), clean_comment_cache(), wp_update_comment_count(), do_action(), get_comment(), wp_transition_comment_status() |
!empty($comment) && !empty($commentarr) && get_post() && !has_filter() && !is_wp_error() && $result !== false | 133–146 | get_comment(), get_post(), has_filter(), user_can(), add_filter(), wp_slash(), array_merge(), wp_filter_comment(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID(), clean_comment_cache(), wp_update_comment_count(), do_action(), get_comment(), wp_transition_comment_status() |
!empty($comment) && !empty($commentarr) && get_post() && !has_filter() && !$value && !is_wp_error() && $result !== false | 137–150 | get_comment(), get_post(), has_filter(), user_can(), add_filter(), wp_slash(), array_merge(), wp_filter_comment(), remove_filter(), wp_unslash(), apply_filters(), get_gmt_from_date(), apply_filters(), is_wp_error(), wp_array_slice_assoc(), comment_ID(), clean_comment_cache(), wp_update_comment_count(), do_action(), get_comment(), wp_transition_comment_status() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 199 instructions, 15–150 executed per call, 20 branches. The work does not change between versions.
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 · 3
3 hooks fire while wp_update_comment() runs, in this order:
- apply_filters( comment_save_pre )filterline 2925 (+56 into the body)
Filters the comment content before it is updated in the database.
- apply_filters( wp_update_comment_data )filterline 2953 (+84 into the body)
Filters the comment data immediately before it is updated in the database.
- do_action( edit_comment )actionline 3014 (+145 into the body)
Fires immediately after a comment is updated in the database.
Uses · 20
- get_comment()Retrieves comment data given a comment ID or comment object.
- __()Retrieves the translation of $text.
- get_post()Retrieves post data given a post ID or post object.
- has_filter()Checks if any filter has been registered for a hook.
- user_can()Returns whether a particular user has the specified capability.
- add_filter()Adds a callback function to a filter hook.
- wp_slash()Adds slashes to a string or recursively adds slashes to strings within an array.
- wp_filter_comment()Filters and sanitizes comment data.
- remove_filter()Removes a callback function from a filter hook.
- wp_unslash()Removes slashes from a string or recursively removes slashes from strings within an array.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- get_gmt_from_date()Given a date in the timezone of the site, returns that date in UTC.
Show all 20
- is_wp_error()Checks whether the given variable is a WordPress Error.
- wp_array_slice_assoc()Extracts a slice of an array, given a list of keys.
- update_comment_meta()Updates comment meta field based on comment ID.
- clean_comment_cache()Removes a comment from the object cache.
- wp_update_comment_count()Updates the comment count for post(s).
- do_action()Calls the callback functions that have been added to an action hook.
- wp_transition_comment_status()Calls hooks for when a comment status transition occurs.
- WP_Error::__construct()Initializes the error.
Used by · 3
- WP_REST_Comments_Controller::update_item()Updates a comment.
- edit_comment()Updates a comment with values provided in $_POST.
- wp_xmlrpc_server::wp_editComment()Edits a comment.
Source code
function wp_update_comment( $commentarr, $wp_error = false ) { global $wpdb; // First, get all of the original fields. $comment = get_comment( $commentarr['comment_ID'], ARRAY_A ); if ( empty( $comment ) ) { if ( $wp_error ) { return new WP_Error( 'invalid_comment_id', __( 'Invalid comment ID.' ) ); } else { return false; } } // Make sure that the comment post ID is valid (if specified). if ( ! empty( $commentarr['comment_post_ID'] ) && ! get_post( $commentarr['comment_post_ID'] ) ) { if ( $wp_error ) { return new WP_Error( 'invalid_post_id', __( 'Invalid post ID.' ) ); } else { return false; } } $filter_comment = false; if ( ! has_filter( 'pre_comment_content', 'wp_filter_kses' ) ) { $filter_comment = ! user_can( $comment['user_id'] ?? 0, 'unfiltered_html' ); } if ( $filter_comment ) { add_filter( 'pre_comment_content', 'wp_filter_kses' ); } // Escape data pulled from DB. $comment = wp_slash( $comment ); $old_status = $comment['comment_approved']; // Merge old and new fields with new fields overwriting old ones. $commentarr = array_merge( $comment, $commentarr ); $commentarr = wp_filter_comment( $commentarr ); if ( $filter_comment ) { remove_filter( 'pre_comment_content', 'wp_filter_kses' ); } // Now extract the merged array. $data = wp_unslash( $commentarr ); /** * Filters the comment content before it is updated in the database. * * @since 1.5.0 * * @param string $comment_content The comment data. */ $data['comment_content'] = apply_filters( 'comment_save_pre', $data['comment_content'] ); $data['comment_date_gmt'] = get_gmt_from_date( $data['comment_date'] ); if ( ! isset( $data['comment_approved'] ) ) { $data['comment_approved'] = 1; } elseif ( 'hold' === $data['comment_approved'] ) { $data['comment_approved'] = 0; } elseif ( 'approve' === $data['comment_approved'] ) { $data['comment_approved'] = 1; } $comment_id = $data['comment_ID']; $comment_post_id = $data['comment_post_ID']; /** * Filters the comment data immediately before it is updated in the database. * * Note: data being passed to the filter is already unslashed. * * @since 4.7.0 * @since 5.5.0 Returning a WP_Error value from the filter will short-circuit comment update * and allow skipping further processing. *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.
$wp_error parameter was added.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 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.