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
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
- Scaling
- Constant
- Instructions
- 48–207
- Plugin surface
- 3 hooks
- Called by
- 0
Reads stored settings via get_option(), cached per request but not free on a cold cache.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 318.
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.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- optionoption read or write
get_option()called directly - hookthird-party callbacks
apply_filters()called directly - cacheobject cache
wp_cache_get()one call below WP_REST_Comments_Controller::create_item() - serializeserialisation
maybe_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.
| When | Instructions | Calls 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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 317 | 48–206 | 32 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 318 | 48–207 | 32 | |
| 8.4 | 318 | 48–207 | 32 | |
| 8.3 | 318 | 48–207 | 32 | |
| 8.2 | 318 | 48–207 | 32 | |
| 8.1 | 318 | 48–207 | 32 | |
| 7.4 | 318 | 48–207 | 32 |
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:
- apply_filters( rest_pre_insert_comment )filterline 788 (+138 into the body)
Filters a comment before it is inserted via the REST API.
- do_action( rest_insert_comment )actionline 819 (+169 into the body)
Fires after a comment is created or updated via the REST API.
- 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
- __()Retrieves the translation of $text.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- current_time()Retrieves the current time based on specified type.
- is_user_logged_in()Determines whether the current visitor is a logged in user.
- wp_get_current_user()Retrieves the current user object.
- get_option()Retrieves an option value based on an option name.
- wp_check_comment_data_max_lengths()Compares the lengths of comment data against the maximum character limits.
- wp_allow_comment()Validates whether this comment is allowed to be made.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- wp_insert_comment()Inserts a comment into the database.
- wp_filter_comment()Filters and sanitizes comment data.
- wp_slash()Adds slashes to a string or recursively adds slashes to strings within an array.
Show all 24
- get_comment()Retrieves comment data given a comment ID or comment object.
- do_action()Calls the callback functions that have been added to an action hook.
- current_user_can()Returns whether the current user has the specified capability.
- rest_ensure_response()Ensures a REST response is a response object (for consistency).
- rest_url()Retrieves the URL to a REST endpoint.
- WP_Error::__construct()Initializes the error.
- WP_REST_Comments_Controller::prepare_item_for_database()Prepares a single comment to be inserted into the database.
- WP_REST_Comments_Controller::check_is_comment_content_allowed()If empty comments are not allowed, checks if the provided comment content is not empty.
- WP_REST_Comments_Controller::handle_status_param()Sets the comment_status of a given comment object when creating or updating a comment.
- WP_REST_Comments_Controller::get_item_schema()Retrieves the comment's schema, conforming to JSON Schema.
- WP_REST_Comments_Controller::update_additional_fields_for_object()
- WP_REST_Comments_Controller::prepare_item_for_response()Prepares a single comment output for response.
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.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.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.