wppaste
WordPress

WP_REST_Comments_Controller::update_item( WP_REST_Request $request ): WP_REST_Response|WP_Error

Since
4.7.0
Source
wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php:803
Updates a comment.

Compatibility

WordPress
since 4.7.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

$requestWP_REST_Request
Full details about the request.

Return value

WP_REST_Response|WP_Error
Response object on success, or error object on failure.

Performance profile

How much work a call to WP_REST_Comments_Controller::update_item() 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 get_post().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
12–141

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

Plugin surface
2 hooks

Third-party callbacks on 'rest_insert_comment', 'rest_after_insert_comment' run inside this call, and their cost is not bounded by anything here.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • querycontent queryget_post()called directly
  • hookthird-party callbacksdo_action()called directly

Further down the call graph this can also reach cache, option, serialize 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 · 106 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_REST_Comments_Controller::update_item() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
is_wp_error()12->get_comment(), is_wp_error()
!isset($request)23->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error()
!is_wp_error() && isset($request)29->get_comment(), is_wp_error(), get_comment_type(), __()
isset($request)29->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error()
!isset($request)33–35->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), is_wp_error()
isset($request)39–41->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), is_wp_error()
!isset($request) && !empty($prepared_args) && !empty($post)41–43->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), get_post(), is_wp_error()
!is_wp_error() && !isset($request) && !empty($prepared_args) && empty($post)41->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), get_post(), __()
!is_wp_error() && !isset($request) && isset($prepared_args)45–47->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), is_wp_error(), __()
!is_wp_error() && empty($prepared_args)45->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), ->handle_status_param(), __()
isset($request) && !empty($prepared_args) && !empty($post)47–49->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), get_post(), is_wp_error()
!is_wp_error() && isset($request) && !empty($prepared_args) && empty($post)47->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), get_post(), __()
94 further outcomes, up to 141 instructions
!is_wp_error() && isset($request) && isset($prepared_args)51–53->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), is_wp_error(), __()
!is_wp_error() && isset($request) && empty($prepared_args)51->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), ->handle_status_param(), __()
!is_wp_error() && !isset($request) && !empty($post) && isset($prepared_args)53–55->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), get_post(), is_wp_error(), __()
!is_wp_error() && !empty($post)53->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), get_post(), ->handle_status_param(), __()
!isset($request) && empty($prepared_args)54–58->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error()
!isset($request)56–60->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), ->get_error_code(), __()
!is_wp_error() && isset($request) && !empty($post) && isset($prepared_args)59–61->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), get_post(), is_wp_error(), __()
!is_wp_error() && isset($request) && !empty($post)59->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), get_post(), ->handle_status_param(), __()
empty($prepared_args) && !empty($value)59–61->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error()
isset($request) && empty($prepared_args)60–64->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error()
empty($prepared_args)62–64->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error()
!isset($request) && !empty($post)62–66->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), get_post(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error()
isset($request)62–66->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), ->get_error_code(), __()
!isset($request) && !empty($prepared_args) && !empty($post)64–68->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), get_post(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), ->get_error_code(), __()
isset($request) && empty($prepared_args) && !empty($value)65–67->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error()
!isset($request)66–70->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), __()
empty($prepared_args) && !empty($value)67->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error()
!empty($post) && !empty($value)67–69->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), get_post(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error()
empty($prepared_args) && !empty($value)68–70->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error()
isset($request) && empty($prepared_args)68–70->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error()
isset($request) && !empty($post)68–72->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), get_post(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error()
!empty($post)70–72->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), get_post(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error()
isset($request) && !empty($prepared_args) && !empty($post)70–74->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), get_post(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), ->get_error_code(), __()
isset($request)72–76->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), __()
!is_wp_error() && !isset($request) && empty($prepared_args)72–76->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response()
isset($request) && empty($prepared_args) && !empty($value)73->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error()
isset($request) && !empty($post) && !empty($value)73–75->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), get_post(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error()
!isset($request) && !empty($prepared_args) && !empty($post)74–78->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), get_post(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), __()
isset($request) && empty($prepared_args) && !empty($value)74–76->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error()
!empty($post) && !empty($value)75->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), get_post(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error()
empty($prepared_args) && !empty($value)76->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error()
!empty($post) && !empty($value)76–78->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), get_post(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error()
isset($request) && !empty($post)76–78->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), get_post(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error()
!is_wp_error() && isset($request) && empty($prepared_args)78–82->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response()
isset($request) && !empty($prepared_args) && !empty($post)80–84->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), get_post(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), __()
!is_wp_error() && empty($prepared_args)80–82->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response()
!is_wp_error() && !isset($request) && !empty($post)80–84->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), get_post(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response()
isset($request) && !empty($post) && !empty($value)81->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), get_post(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error()
isset($request) && empty($prepared_args) && !empty($value)82->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error()
isset($request) && !empty($post) && !empty($value)82–84->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), get_post(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error()
!empty($post) && !empty($value)84->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), get_post(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error()
!isset($request)85–91->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error()
!is_wp_error() && empty($prepared_args) && !empty($value)86–88->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response()
!is_wp_error() && isset($request) && empty($prepared_args)86–88->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response()
!is_wp_error() && isset($request) && !empty($post)86–90->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), get_post(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response()
!is_wp_error() && !empty($post)88–90->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), get_post(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response()
isset($request) && !empty($post) && !empty($value)90->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), get_post(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error()
!empty($value)90–94->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error()
always91–97->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error()
always91–97->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error()
!is_wp_error() && isset($request) && empty($prepared_args) && !empty($value)92–94->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response()
!isset($request) && !empty($prepared_args) && !empty($post)93–99->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), get_post(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error()
!is_wp_error() && empty($prepared_args) && !empty($value)94->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response()
!is_wp_error() && !empty($post) && !empty($value)94–96->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), get_post(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response()
!is_wp_error() && isset($request) && !empty($post)94–96->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), get_post(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response()
!empty($value)96–100->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error()
!empty($value)96–100->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error()
isset($request)97–103->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error()
!empty($prepared_args) && !empty($post) && !empty($value)98–102->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), get_post(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error()
!empty($value)99–103->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error()
!empty($prepared_args) && !empty($post)99–105->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), get_post(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error()
!empty($prepared_args) && !empty($post)99–105->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), get_post(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error()
!is_wp_error() && isset($request) && empty($prepared_args) && !empty($value)100->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response()
!is_wp_error() && isset($request) && !empty($post) && !empty($value)100–102->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), get_post(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response()
!is_wp_error() && !empty($post) && !empty($value)102->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), get_post(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response()
isset($request) && !empty($value)102–106->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error()
!is_wp_error() && !isset($request)103–109->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response()
!empty($prepared_args) && !empty($post) && !empty($value)104–108->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), get_post(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error()
!empty($prepared_args) && !empty($post) && !empty($value)104–108->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), get_post(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error()
!empty($value)105–109->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error()
!empty($value)105–109->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error()
isset($request) && !empty($prepared_args) && !empty($post)105–111->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), get_post(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error()
!empty($prepared_args) && !empty($post) && !empty($value)107–111->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), get_post(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error()
!is_wp_error() && isset($request) && !empty($post) && !empty($value)108->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), get_post(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response()
!is_wp_error()109–115->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response()
!is_wp_error()109–115->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response()
isset($request) && !empty($prepared_args) && !empty($post) && !empty($value)110–114->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), get_post(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error()
isset($request) && !empty($value)111–115->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error()
!is_wp_error() && !isset($request) && !empty($prepared_args) && !empty($post)111–117->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), get_post(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response()
!empty($prepared_args) && !empty($post) && !empty($value)113–117->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), get_post(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error()
!empty($prepared_args) && !empty($post) && !empty($value)113–117->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), get_post(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error()
!is_wp_error() && isset($request)115–121->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response()
!is_wp_error() && !empty($value)117–121->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response()
!is_wp_error() && !empty($prepared_args) && !empty($post)117–123->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), get_post(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response()
!is_wp_error() && !empty($prepared_args) && !empty($post)117–123->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), get_post(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response()
isset($request) && !empty($prepared_args) && !empty($post) && !empty($value)119–123->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), get_post(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error()
!is_wp_error() && !empty($value)123–127->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response()
!is_wp_error() && !empty($value)123–127->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response()
!is_wp_error() && isset($request) && !empty($prepared_args) && !empty($post)123–129->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), get_post(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response()
!is_wp_error() && !empty($prepared_args) && !empty($post) && !empty($value)125–129->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), get_post(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response()
!is_wp_error() && isset($request) && !empty($value)129–133->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response()
!is_wp_error() && !empty($prepared_args) && !empty($post) && !empty($value)131–135->get_comment(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), get_post(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response()
!is_wp_error() && !empty($prepared_args) && !empty($post) && !empty($value)131–135->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), get_post(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response()
!is_wp_error() && isset($request) && !empty($prepared_args) && !empty($post) && !empty($value)137–141->get_comment(), is_wp_error(), get_comment_type(), ->prepare_item_for_database(), is_wp_error(), get_post(), is_wp_error(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_slash(), wp_update_comment(), is_wp_error(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response()

Across PHP versions

Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 211 instructions, 12–141 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 · 2

2 hooks fire while WP_REST_Comments_Controller::update_item() runs, in this order:

  1. do_action( rest_insert_comment )actionline 892 (+89 into the body)

    Fires after a comment is created or updated via the REST API.

  2. do_action( rest_after_insert_comment )actionline 913 (+110 into the body)

    Fires completely after a comment is created or updated via the REST API.

Uses · 17

Show all 17

Source code

	public function update_item( $request ) {		$comment = $this->get_comment( $request['id'] );		if ( is_wp_error( $comment ) ) {			return $comment;		} 		$id = $comment->comment_ID; 		if ( isset( $request['type'] ) && get_comment_type( $id ) !== $request['type'] ) {			return new WP_Error(				'rest_comment_invalid_type',				__( 'Sorry, you are not allowed to change the comment type.' ),				array( 'status' => 404 )			);		} 		$prepared_args = $this->prepare_item_for_database( $request ); 		if ( is_wp_error( $prepared_args ) ) {			return $prepared_args;		} 		if ( ! empty( $prepared_args['comment_post_ID'] ) ) {			$post = get_post( $prepared_args['comment_post_ID'] ); 			if ( empty( $post ) ) {				return new WP_Error(					'rest_comment_invalid_post_id',					__( 'Invalid post ID.' ),					array( 'status' => 403 )				);			}		} 		if ( empty( $prepared_args ) && isset( $request['status'] ) ) {			// Only the comment status is being changed.			$change = $this->handle_status_param( $request['status'], $id ); 			if ( ! $change ) {				return new WP_Error(					'rest_comment_failed_edit',					__( 'Updating comment status failed.' ),					array( 'status' => 500 )				);			}		} elseif ( ! empty( $prepared_args ) ) {			if ( is_wp_error( $prepared_args ) ) {				return $prepared_args;			} 			if ( isset( $prepared_args['comment_content'] ) && empty( $prepared_args['comment_content'] ) ) {				return new WP_Error(					'rest_comment_content_invalid',					__( 'Invalid comment content.' ),					array( 'status' => 400 )				);			} 			$prepared_args['comment_ID'] = $id; 			$check_comment_lengths = wp_check_comment_data_max_lengths( $prepared_args ); 			if ( is_wp_error( $check_comment_lengths ) ) {				$error_code = $check_comment_lengths->get_error_code();				return new WP_Error(					$error_code,					__( 'Comment field exceeds maximum length allowed.' ),					array( 'status' => 400 )				);			} 			$updated = wp_update_comment( wp_slash( (array) $prepared_args ), true ); 			if ( is_wp_error( $updated ) ) {				return new WP_Error(					'rest_comment_failed_edit',					__( 'Updating comment failed.' ),					array( 'status' => 500 )				);			}

Changelog

Introduced in 4.7.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.

About this page

Parsed data
Generated from the wordpress-develop 6.7.7 tag, from src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.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.