wppaste
WordPress

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
Updates an existing comment in the database.

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

Reaches the database via ->update().

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
15–150

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 199.

Plugin surface
3 hooks

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.

Called by
3

3 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • querycontent queryget_post()called directly
  • hookthird-party callbacksapply_filters()called directly
  • sqldatabase query->update()called directly
  • cacheobject cachewp_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.

WhenInstructionsCalls it makes
empty($comment)15get_comment()
empty($comment)22get_comment(), __()
!empty($comment) && !empty($commentarr) && !get_post()23get_comment(), get_post()
!empty($comment) && !empty($commentarr) && !get_post()30get_comment(), get_post(), __()
!empty($comment) && empty($commentarr) && has_filter() && $value && is_wp_error()76–81get_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–85get_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–85get_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–87get_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–89get_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–89get_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–91get_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–91get_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–93get_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–93get_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–95get_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–95get_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–97get_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 === false93–98get_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–99get_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–99get_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 === false97–102get_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 === false97–102get_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–103get_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 === false99–104get_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 === false100–106get_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 === false101–106get_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 === false103–108get_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 === false103–108get_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 === false103–108get_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 === false104–110get_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 === false104–110get_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 === false106–112get_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 === false107–112get_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 === false107–112get_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 === false107–112get_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 === false108–114get_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 === false109–114get_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 === false110–116get_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 === false110–116get_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 === false110–116get_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 === false111–116get_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 === false113–118get_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 === false113–118get_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 === false114–120get_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 === false114–120get_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 === false114–120get_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 === false116–122get_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 !== false116–128get_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 === false117–122get_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 === false118–124get_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 === false120–126get_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 === false120–126get_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 !== false120–132get_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 !== false120–132get_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 !== false122–134get_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 !== false123–136get_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 === false124–130get_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 !== false124–136get_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 !== false126–138get_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 !== false126–138get_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 !== false127–140get_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 !== false127–140get_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 !== false129–142get_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 !== false130–142get_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 !== false131–144get_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 !== false133–146get_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 !== false133–146get_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 !== false137–150get_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:

  1. apply_filters( comment_save_pre )filterline 2925 (+56 into the body)

    Filters the comment content before it is updated in the database.

  2. apply_filters( wp_update_comment_data )filterline 2953 (+84 into the body)

    Filters the comment data immediately before it is updated in the database.

  3. 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

Used by · 3

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

5.5.0
The return values for an invalid comment or post ID were changed to false instead of 0.from the docblock
5.5.0
The $wp_error parameter was added.from the docblock
4.9.0
Add updating comment meta during comment update.from the docblock
2.0.0
Introduced.from the docblock

About 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.