wppaste
WordPress

WP_REST_Comments_Controller::create_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:650
Creates 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::create_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
Moderate

Reads stored settings via get_option(), cached per request but not free on a cold cache.

Scaling
Constant

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

Instructions
48–207

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

Plugin surface
3 hooks

Third-party callbacks on 'rest_pre_insert_comment', '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

  • optionoption read or writeget_option()called directly
  • hookthird-party callbacksapply_filters()called directly
  • cacheobject cachewp_cache_get()one call below WP_REST_Comments_Controller::create_item()
  • serializeserialisationmaybe_unserialize()one call below WP_REST_Comments_Controller::create_item()

Further down the call graph this can also reach query 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 · 56 distinct outcomes

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

WhenInstructionsCalls it makes
empty($request) && !is_wp_error() && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && get_option()48–52->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), get_option(), __()
empty($request) && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment)63–75->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), ->get_error_code(), __()
empty($request) && !is_wp_error() && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && is_user_logged_in() && get_option()64–66->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), wp_get_current_user(), get_option(), __()
empty($request) && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment)75–87->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), is_wp_error(), apply_filters(), is_wp_error()
empty($request) && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment)78–94->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), is_wp_error(), ->get_error_code(), ->get_error_message()
empty($request) && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment)78–90->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_allow_comment(), is_wp_error(), apply_filters(), is_wp_error()
empty($request) && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && is_user_logged_in()79–89->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), wp_get_current_user(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), ->get_error_code(), __()
empty($request) && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment)81–97->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_allow_comment(), is_wp_error(), ->get_error_code(), ->get_error_message()
empty($request) && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && is_user_logged_in()91–101->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), wp_get_current_user(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), is_wp_error(), apply_filters(), is_wp_error()
empty($request) && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && is_user_logged_in()94–108->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), wp_get_current_user(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), is_wp_error(), ->get_error_code(), ->get_error_message()
empty($request) && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && is_user_logged_in()94–104->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), wp_get_current_user(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_allow_comment(), is_wp_error(), apply_filters(), is_wp_error()
empty($request) && !is_wp_error() && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment)95–107->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), __()
44 further outcomes, up to 207 instructions
empty($request) && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && is_user_logged_in()97–111->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), wp_get_current_user(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_allow_comment(), is_wp_error(), ->get_error_code(), ->get_error_message()
empty($request) && !is_wp_error() && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment)98–110->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_allow_comment(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), __()
empty($request) && !is_wp_error() && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && is_user_logged_in()111–121->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), wp_get_current_user(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), __()
empty($request) && !is_wp_error() && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && is_user_logged_in()114–124->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), wp_get_current_user(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_allow_comment(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), __()
empty($request) && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && !isset($request)114–128->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error()
empty($request) && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && !isset($request)117–131->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_allow_comment(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error()
empty($request) && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && !empty($value)119–131->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error()
empty($request) && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && isset($request)120–134->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error()
empty($request) && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && !empty($value)122–134->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_allow_comment(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error()
empty($request) && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && isset($request)123–137->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_allow_comment(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error()
empty($request) && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && isset($request) && !empty($value)125–137->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error()
empty($request) && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && isset($request) && !empty($value)128–140->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_allow_comment(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error()
empty($request) && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && !empty($value)128–140->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error()
empty($request) && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && is_user_logged_in() && !isset($request)130–142->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), wp_get_current_user(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error()
empty($request) && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && !empty($value)131–143->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_allow_comment(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error()
empty($request) && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && is_user_logged_in() && !isset($request)133–145->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), wp_get_current_user(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_allow_comment(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error()
empty($request) && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && isset($request) && !empty($value)134–146->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error()
empty($request) && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && is_user_logged_in() && !empty($value)135–145->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), wp_get_current_user(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error()
empty($request) && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && is_user_logged_in() && isset($request)136–148->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), wp_get_current_user(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error()
empty($request) && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && isset($request) && !empty($value)137–149->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_allow_comment(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error()
empty($request) && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && is_user_logged_in() && !empty($value)138–148->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), wp_get_current_user(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_allow_comment(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error()
empty($request) && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && is_user_logged_in() && isset($request)139–151->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), wp_get_current_user(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_allow_comment(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error()
empty($request) && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && is_user_logged_in() && isset($request) && !empty($value)141–151->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), wp_get_current_user(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error()
empty($request) && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && is_user_logged_in() && isset($request) && !empty($value)144–154->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), wp_get_current_user(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_allow_comment(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error()
empty($request) && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && is_user_logged_in() && !empty($value)144–154->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), wp_get_current_user(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error()
empty($request) && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && is_user_logged_in() && !empty($value)147–157->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), wp_get_current_user(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_allow_comment(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error()
empty($request) && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && is_user_logged_in() && isset($request) && !empty($value)150–160->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), wp_get_current_user(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error()
empty($request) && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && is_user_logged_in() && isset($request) && !empty($value)153–163->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), wp_get_current_user(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_allow_comment(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error()
empty($request) && !is_wp_error() && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && !isset($request)157–172->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error(), current_user_can(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response(), ->set_status(), rest_url(), ->header()
empty($request) && !is_wp_error() && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && !isset($request)160–175->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_allow_comment(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error(), current_user_can(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response(), ->set_status(), rest_url(), ->header()
empty($request) && !is_wp_error() && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && isset($request)163–178->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error(), current_user_can(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response(), ->set_status(), rest_url(), ->header()
empty($request) && !is_wp_error() && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && isset($request)166–181->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_allow_comment(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error(), current_user_can(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response(), ->set_status(), rest_url(), ->header()
empty($request) && !is_wp_error() && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && !empty($value)171–184->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error(), current_user_can(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response(), ->set_status(), rest_url(), ->header()
empty($request) && !is_wp_error() && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && is_user_logged_in() && !isset($request)173–186->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), wp_get_current_user(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error(), current_user_can(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response(), ->set_status(), rest_url(), ->header()
empty($request) && !is_wp_error() && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && !empty($value)174–187->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_allow_comment(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error(), current_user_can(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response(), ->set_status(), rest_url(), ->header()
empty($request) && !is_wp_error() && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && is_user_logged_in() && !isset($request)176–189->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), wp_get_current_user(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_allow_comment(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error(), current_user_can(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response(), ->set_status(), rest_url(), ->header()
empty($request) && !is_wp_error() && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && isset($request) && !empty($value)177–190->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error(), current_user_can(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response(), ->set_status(), rest_url(), ->header()
empty($request) && !is_wp_error() && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && is_user_logged_in() && isset($request)179–192->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), wp_get_current_user(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error(), current_user_can(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response(), ->set_status(), rest_url(), ->header()
empty($request) && !is_wp_error() && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && isset($request) && !empty($value)180–193->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_allow_comment(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error(), current_user_can(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response(), ->set_status(), rest_url(), ->header()
empty($request) && !is_wp_error() && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && is_user_logged_in() && isset($request)182–195->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), wp_get_current_user(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_allow_comment(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_additional_fields_for_object(), is_wp_error(), current_user_can(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response(), ->set_status(), rest_url(), ->header()
empty($request) && !is_wp_error() && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && is_user_logged_in() && !empty($value)187–198->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), wp_get_current_user(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error(), current_user_can(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response(), ->set_status(), rest_url(), ->header()
empty($request) && !is_wp_error() && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && is_user_logged_in() && !empty($value)190–201->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), wp_get_current_user(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_allow_comment(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error(), current_user_can(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response(), ->set_status(), rest_url(), ->header()
empty($request) && !is_wp_error() && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && is_user_logged_in() && isset($request) && !empty($value)193–204->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), wp_get_current_user(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error(), current_user_can(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response(), ->set_status(), rest_url(), ->header()
empty($request) && !is_wp_error() && isset($prepared_comment) && !isset($value) && ->check_is_comment_content_allowed() && !empty($prepared_comment) && is_user_logged_in() && isset($request) && !empty($value)196–207->prepare_item_for_database(), is_wp_error(), ->check_is_comment_content_allowed(), is_user_logged_in(), wp_get_current_user(), get_option(), wp_check_comment_data_max_lengths(), is_wp_error(), wp_allow_comment(), is_wp_error(), apply_filters(), is_wp_error(), wp_slash(), wp_filter_comment(), wp_insert_comment(), ->handle_status_param(), get_comment(), do_action(), ->get_item_schema(), ->update_value(), is_wp_error(), ->update_additional_fields_for_object(), is_wp_error(), current_user_can(), ->set_param(), do_action(), ->prepare_item_for_response(), rest_ensure_response(), ->set_status(), rest_url(), ->header()

This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev31748–206321 fewer instruction than PHP 8.5
8.531848–20732
8.431848–20732
8.331848–20732
8.231848–20732
8.131848–20732
7.431848–20732

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_REST_Comments_Controller::create_item() runs, in this order:

  1. apply_filters( rest_pre_insert_comment )filterline 788 (+138 into the body)

    Filters a comment before it is inserted via the REST API.

  2. do_action( rest_insert_comment )actionline 819 (+169 into the body)

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

  3. do_action( rest_after_insert_comment )actionline 850 (+200 into the body)

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

Uses · 24

Show all 24

Source code

	public function create_item( $request ) {		if ( ! empty( $request['id'] ) ) {			return new WP_Error(				'rest_comment_exists',				__( 'Cannot create existing comment.' ),				array( 'status' => 400 )			);		} 		// Do not allow comments to be created with a non-core type.		if ( ! empty( $request['type'] ) && ! in_array( $request['type'], array( 'comment', 'note' ), true ) ) {			return new WP_Error(				'rest_invalid_comment_type',				__( 'Cannot create a comment with that type.' ),				array( 'status' => 400 )			);		} 		$prepared_comment = $this->prepare_item_for_database( $request );		if ( is_wp_error( $prepared_comment ) ) {			return $prepared_comment;		} 		$prepared_comment['comment_type'] = $request['type']; 		if ( ! isset( $prepared_comment['comment_content'] ) ) {			$prepared_comment['comment_content'] = '';		} 		// Include note metadata into check_is_comment_content_allowed.		if ( isset( $request['meta']['_wp_note_status'] ) ) {			$prepared_comment['meta']['_wp_note_status'] = $request['meta']['_wp_note_status'];		} 		if ( ! $this->check_is_comment_content_allowed( $prepared_comment ) ) {			return new WP_Error(				'rest_comment_content_invalid',				__( 'Invalid comment content.' ),				array( 'status' => 400 )			);		} 		// Setting remaining values before wp_insert_comment so we can use wp_allow_comment().		if ( ! isset( $prepared_comment['comment_date_gmt'] ) ) {			$prepared_comment['comment_date_gmt'] = current_time( 'mysql', true );		} 		// Set author data if the user's logged in.		$missing_author = empty( $prepared_comment['user_id'] )			&& empty( $prepared_comment['comment_author'] )			&& empty( $prepared_comment['comment_author_email'] )			&& empty( $prepared_comment['comment_author_url'] ); 		if ( is_user_logged_in() && $missing_author ) {			$user = wp_get_current_user(); 			$prepared_comment['user_id']              = $user->ID;			$prepared_comment['comment_author']       = $user->display_name;			$prepared_comment['comment_author_email'] = $user->user_email;			$prepared_comment['comment_author_url']   = $user->user_url;		} 		// Honor the discussion setting that requires a name and email address of the comment author.		if ( get_option( 'require_name_email' ) ) {			if ( empty( $prepared_comment['comment_author'] ) || empty( $prepared_comment['comment_author_email'] ) ) {				return new WP_Error(					'rest_comment_author_data_required',					__( 'Creating a comment requires valid author name and email values.' ),					array( 'status' => 400 )				);			}		} 		if ( ! isset( $prepared_comment['comment_author_email'] ) ) {			$prepared_comment['comment_author_email'] = '';		} 		if ( ! isset( $prepared_comment['comment_author_url'] ) ) {			$prepared_comment['comment_author_url'] = '';		}

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