comment_form( array $args = array(), int|WP_Post $post = null )
- Since
- 3.0.0, 4.1.0, 4.2.0, 4.4.0, 4.5.0, 4.6.0, 4.9.6, 5.5.0, 6.8.2
- Source
wp-includes/comment-template.php:2494
Description
Most strings and form fields may be controlled through the $args array passed into the function, while you may also choose to use the 'comment_form_default_fields' filter to modify the array of default fields if you'd just like to add a new one or remove a single field. All fields are also individually passed through a filter of the 'comment_formfield$name' where $name is the key used in the array of fields.
Compatibility
- WordPress
- since 6.8.2
- 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
$argsarrayoptional- Default arguments and form fields to override.Default:
array()$fieldsarray{ Default comment fields, filterable by default via the 'comment_form_default_fields' hook.$authorstringComment author field HTML.$emailstringComment author email field HTML.$urlstringComment author URL field HTML.$cookiesstringComment cookie opt-in field HTML. } @type string $comment_field The comment textarea field HTML.$must_log_instringHTML element for a 'must be logged in to comment' message.$logged_in_asstringThe HTML for the 'logged in as [user]' message, the Edit profile link, and the Log out link.$comment_notes_beforestringdefault: 'Your email address will not be published.'HTML element for a message displayed before the comment fields if the user is not logged in.$comment_notes_afterstringHTML element for a message displayed after the textarea field.$actionstringdefault: '/wp-comments-post.php'The comment form element action attribute.$novalidatebooldefault: falseWhether the novalidate attribute is added to the comment form.$id_formstringdefault: 'commentform'The comment form element id attribute.$id_submitstringdefault: 'submit'The comment submit element id attribute.$class_containerstringdefault: 'comment-respond'The comment form container class attribute.$class_formstringdefault: 'comment-form'The comment form element class attribute.$class_submitstringdefault: 'submit'The comment submit element class attribute.$name_submitstringdefault: 'submit'The comment submit element name attribute.$title_replystringdefault: 'Leave a Reply'The translatable 'reply' button label.$title_reply_tostringdefault: 'Leave a Reply to %s', where %s is the author of the comment being replied toThe translatable 'reply-to' button label.$title_reply_beforestringdefault: ''HTML displayed before the comment form title.$title_reply_afterstringdefault: ''HTML displayed after the comment form title.$cancel_reply_beforestringHTML displayed before the cancel reply link.$cancel_reply_afterstringHTML displayed after the cancel reply link.$cancel_reply_linkstringdefault: 'Cancel reply'The translatable 'cancel reply' button label.$label_submitstringdefault: 'Post a comment'The translatable 'submit' button label.$submit_buttonstringdefault: ''HTML format for the Submit button.$submit_fieldstringHTML format for the markup surrounding the Submit button and comment hidden fields. Default: '%1$s %2$s
', where %1$s is the submit button markup and %2$s is the comment hidden fields.$formatstringdefault: 'xhtml'. Accepts 'xhtml', 'html5'The comment form format.
$postint|WP_Postoptional- Post ID or WP_Post object to generate the form for. Default current post.Default:
null
Performance profile
How much work a call to comment_form() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Scales with input
- Instructions
- 11–492
- Plugin surface
- 18 hooks
- Called by
- 2
Reaches the database via get_post().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 573.
Third-party callbacks on 'comment_form_comments_closed', 'comment_form_default_fields', 'the_permalink' run inside this call, and their cost is not bounded by anything here.
2 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- querycontent query
get_post()called directly - hookthird-party callbacks
do_action()called directly - optionoption read or write
get_option()called directly - cacheobject cache
wp_cache_get()one call below comment_form() - serializeserialisation
maybe_unserialize()one call below comment_form()
Further down the call graph this can also reach transient. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 31 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost comment_form() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 11 | get_post(), do_action() |
comments_open() && !->exists() && isset($args) && !has_action() && !is_user_logged_in() | 318–328 | get_post(), comments_open(), wp_get_current_commenter(), wp_get_current_user(), ->exists(), wp_parse_args(), get_option(), wp_required_field_indicator(), wp_required_field_message(), __(), esc_attr(), __(), esc_attr(), __(), esc_attr(), has_action(), apply_filters(), _x(), __(), get_permalink(), apply_filters(), wp_login_url(), sprintf(), __(), get_edit_user_link(), get_permalink(), apply_filters(), wp_logout_url(), sprintf(), __(), site_url(), __(), __(), __(), __(), apply_filters(), wp_parse_args(), array_merge(), do_action(), esc_attr(), comment_form_title(), get_option(), get_option(), is_user_logged_in(), do_action(), do_action() |
comments_open() && !->exists() && isset($args) && has_action() && !is_user_logged_in() | 322–332 | get_post(), comments_open(), wp_get_current_commenter(), wp_get_current_user(), ->exists(), wp_parse_args(), get_option(), wp_required_field_indicator(), wp_required_field_message(), __(), esc_attr(), __(), esc_attr(), __(), esc_attr(), has_action(), get_option(), apply_filters(), _x(), __(), get_permalink(), apply_filters(), wp_login_url(), sprintf(), __(), get_edit_user_link(), get_permalink(), apply_filters(), wp_logout_url(), sprintf(), __(), site_url(), __(), __(), __(), __(), apply_filters(), wp_parse_args(), array_merge(), do_action(), esc_attr(), comment_form_title(), get_option(), get_option(), is_user_logged_in(), do_action(), do_action() |
comments_open() && !->exists() && isset($args) && !has_action() && get_option() && !is_user_logged_in() | 327–337 | get_post(), comments_open(), wp_get_current_commenter(), wp_get_current_user(), ->exists(), wp_parse_args(), get_option(), wp_required_field_indicator(), wp_required_field_message(), __(), esc_attr(), __(), esc_attr(), __(), esc_attr(), has_action(), apply_filters(), _x(), __(), get_permalink(), apply_filters(), wp_login_url(), sprintf(), __(), get_edit_user_link(), get_permalink(), apply_filters(), wp_logout_url(), sprintf(), __(), site_url(), __(), __(), __(), __(), apply_filters(), wp_parse_args(), array_merge(), do_action(), esc_attr(), comment_form_title(), get_option(), cancel_comment_reply_link(), get_option(), is_user_logged_in(), do_action(), do_action() |
comments_open() && !->exists() && isset($args) && has_action() && !is_user_logged_in() | 331–341 | get_post(), comments_open(), wp_get_current_commenter(), wp_get_current_user(), ->exists(), wp_parse_args(), get_option(), wp_required_field_indicator(), wp_required_field_message(), __(), esc_attr(), __(), esc_attr(), __(), esc_attr(), has_action(), get_option(), apply_filters(), _x(), __(), get_permalink(), apply_filters(), wp_login_url(), sprintf(), __(), get_edit_user_link(), get_permalink(), apply_filters(), wp_logout_url(), sprintf(), __(), site_url(), __(), __(), __(), __(), apply_filters(), wp_parse_args(), array_merge(), do_action(), esc_attr(), comment_form_title(), get_option(), cancel_comment_reply_link(), get_option(), is_user_logged_in(), do_action(), do_action() |
comments_open() && !->exists() && isset($args) && has_action() && !empty($commenter) && !is_user_logged_in() | 344–361 | get_post(), comments_open(), wp_get_current_commenter(), wp_get_current_user(), ->exists(), wp_parse_args(), get_option(), wp_required_field_indicator(), wp_required_field_message(), __(), esc_attr(), __(), esc_attr(), __(), esc_attr(), has_action(), get_option(), __(), apply_filters(), _x(), __(), get_permalink(), apply_filters(), wp_login_url(), sprintf(), __(), get_edit_user_link(), get_permalink(), apply_filters(), wp_logout_url(), sprintf(), __(), site_url(), __(), __(), __(), __(), apply_filters(), wp_parse_args(), array_merge(), do_action(), esc_attr(), comment_form_title(), get_option(), get_option(), is_user_logged_in(), do_action(), do_action() |
comments_open() && !->exists() && isset($args) && has_action() && get_option() && !empty($commenter) && !is_user_logged_in() | 353–366 | get_post(), comments_open(), wp_get_current_commenter(), wp_get_current_user(), ->exists(), wp_parse_args(), get_option(), wp_required_field_indicator(), wp_required_field_message(), __(), esc_attr(), __(), esc_attr(), __(), esc_attr(), has_action(), get_option(), __(), apply_filters(), _x(), __(), get_permalink(), apply_filters(), wp_login_url(), sprintf(), __(), get_edit_user_link(), get_permalink(), apply_filters(), wp_logout_url(), sprintf(), __(), site_url(), __(), __(), __(), __(), apply_filters(), wp_parse_args(), array_merge(), do_action(), esc_attr(), comment_form_title(), get_option(), cancel_comment_reply_link(), get_option(), is_user_logged_in(), do_action(), do_action() |
comments_open() && !->exists() && isset($args) && !has_action() && !get_option() && !is_user_logged_in() | 426–438 | get_post(), comments_open(), wp_get_current_commenter(), wp_get_current_user(), ->exists(), wp_parse_args(), get_option(), wp_required_field_indicator(), wp_required_field_message(), __(), esc_attr(), __(), esc_attr(), __(), esc_attr(), has_action(), apply_filters(), _x(), __(), get_permalink(), apply_filters(), wp_login_url(), sprintf(), __(), get_edit_user_link(), get_permalink(), apply_filters(), wp_logout_url(), sprintf(), __(), site_url(), __(), __(), __(), __(), apply_filters(), wp_parse_args(), array_merge(), do_action(), esc_attr(), comment_form_title(), get_option(), get_option(), esc_url(), esc_attr(), esc_attr(), printf(), do_action(), is_user_logged_in(), apply_filters(), array_keys(), array_diff(), reset(), end(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), sprintf(), apply_filters(), get_comment_id_fields(), sprintf(), apply_filters(), do_action(), do_action() |
comments_open() && !->exists() && isset($args) && !has_action() | 429–441 | get_post(), comments_open(), wp_get_current_commenter(), wp_get_current_user(), ->exists(), wp_parse_args(), get_option(), wp_required_field_indicator(), wp_required_field_message(), __(), esc_attr(), __(), esc_attr(), __(), esc_attr(), has_action(), apply_filters(), _x(), __(), get_permalink(), apply_filters(), wp_login_url(), sprintf(), __(), get_edit_user_link(), get_permalink(), apply_filters(), wp_logout_url(), sprintf(), __(), site_url(), __(), __(), __(), __(), apply_filters(), wp_parse_args(), array_merge(), do_action(), esc_attr(), comment_form_title(), get_option(), get_option(), is_user_logged_in(), esc_url(), esc_attr(), esc_attr(), printf(), do_action(), is_user_logged_in(), apply_filters(), array_keys(), array_diff(), reset(), end(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), sprintf(), apply_filters(), get_comment_id_fields(), sprintf(), apply_filters(), do_action(), do_action() |
comments_open() && !->exists() && isset($args) && has_action() && !get_option() && !is_user_logged_in() | 430–442 | get_post(), comments_open(), wp_get_current_commenter(), wp_get_current_user(), ->exists(), wp_parse_args(), get_option(), wp_required_field_indicator(), wp_required_field_message(), __(), esc_attr(), __(), esc_attr(), __(), esc_attr(), has_action(), get_option(), apply_filters(), _x(), __(), get_permalink(), apply_filters(), wp_login_url(), sprintf(), __(), get_edit_user_link(), get_permalink(), apply_filters(), wp_logout_url(), sprintf(), __(), site_url(), __(), __(), __(), __(), apply_filters(), wp_parse_args(), array_merge(), do_action(), esc_attr(), comment_form_title(), get_option(), get_option(), esc_url(), esc_attr(), esc_attr(), printf(), do_action(), is_user_logged_in(), apply_filters(), array_keys(), array_diff(), reset(), end(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), sprintf(), apply_filters(), get_comment_id_fields(), sprintf(), apply_filters(), do_action(), do_action() |
comments_open() && !->exists() && isset($args) && has_action() | 433–445 | get_post(), comments_open(), wp_get_current_commenter(), wp_get_current_user(), ->exists(), wp_parse_args(), get_option(), wp_required_field_indicator(), wp_required_field_message(), __(), esc_attr(), __(), esc_attr(), __(), esc_attr(), has_action(), get_option(), apply_filters(), _x(), __(), get_permalink(), apply_filters(), wp_login_url(), sprintf(), __(), get_edit_user_link(), get_permalink(), apply_filters(), wp_logout_url(), sprintf(), __(), site_url(), __(), __(), __(), __(), apply_filters(), wp_parse_args(), array_merge(), do_action(), esc_attr(), comment_form_title(), get_option(), get_option(), is_user_logged_in(), esc_url(), esc_attr(), esc_attr(), printf(), do_action(), is_user_logged_in(), apply_filters(), array_keys(), array_diff(), reset(), end(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), sprintf(), apply_filters(), get_comment_id_fields(), sprintf(), apply_filters(), do_action(), do_action() |
comments_open() && !->exists() && isset($args) && !has_action() && !is_user_logged_in() | 435–447 | get_post(), comments_open(), wp_get_current_commenter(), wp_get_current_user(), ->exists(), wp_parse_args(), get_option(), wp_required_field_indicator(), wp_required_field_message(), __(), esc_attr(), __(), esc_attr(), __(), esc_attr(), has_action(), apply_filters(), _x(), __(), get_permalink(), apply_filters(), wp_login_url(), sprintf(), __(), get_edit_user_link(), get_permalink(), apply_filters(), wp_logout_url(), sprintf(), __(), site_url(), __(), __(), __(), __(), apply_filters(), wp_parse_args(), array_merge(), do_action(), esc_attr(), comment_form_title(), get_option(), cancel_comment_reply_link(), get_option(), esc_url(), esc_attr(), esc_attr(), printf(), do_action(), is_user_logged_in(), apply_filters(), array_keys(), array_diff(), reset(), end(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), sprintf(), apply_filters(), get_comment_id_fields(), sprintf(), apply_filters(), do_action(), do_action() |
19 further outcomes, up to 492 instructions
comments_open() && !->exists() && isset($args) && !has_action() && get_option() | 438–450 | get_post(), comments_open(), wp_get_current_commenter(), wp_get_current_user(), ->exists(), wp_parse_args(), get_option(), wp_required_field_indicator(), wp_required_field_message(), __(), esc_attr(), __(), esc_attr(), __(), esc_attr(), has_action(), apply_filters(), _x(), __(), get_permalink(), apply_filters(), wp_login_url(), sprintf(), __(), get_edit_user_link(), get_permalink(), apply_filters(), wp_logout_url(), sprintf(), __(), site_url(), __(), __(), __(), __(), apply_filters(), wp_parse_args(), array_merge(), do_action(), esc_attr(), comment_form_title(), get_option(), cancel_comment_reply_link(), get_option(), is_user_logged_in(), esc_url(), esc_attr(), esc_attr(), printf(), do_action(), is_user_logged_in(), apply_filters(), array_keys(), array_diff(), reset(), end(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), sprintf(), apply_filters(), get_comment_id_fields(), sprintf(), apply_filters(), do_action(), do_action() |
comments_open() && !->exists() && isset($args) && !has_action() && !get_option() && is_user_logged_in() | 439–451 | get_post(), comments_open(), wp_get_current_commenter(), wp_get_current_user(), ->exists(), wp_parse_args(), get_option(), wp_required_field_indicator(), wp_required_field_message(), __(), esc_attr(), __(), esc_attr(), __(), esc_attr(), has_action(), apply_filters(), _x(), __(), get_permalink(), apply_filters(), wp_login_url(), sprintf(), __(), get_edit_user_link(), get_permalink(), apply_filters(), wp_logout_url(), sprintf(), __(), site_url(), __(), __(), __(), __(), apply_filters(), wp_parse_args(), array_merge(), do_action(), esc_attr(), comment_form_title(), get_option(), get_option(), esc_url(), esc_attr(), esc_attr(), printf(), do_action(), is_user_logged_in(), apply_filters(), do_action(), apply_filters(), array_keys(), array_diff(), reset(), end(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), sprintf(), apply_filters(), get_comment_id_fields(), sprintf(), apply_filters(), do_action(), do_action() |
comments_open() && !->exists() && isset($args) && has_action() && !is_user_logged_in() | 439–451 | get_post(), comments_open(), wp_get_current_commenter(), wp_get_current_user(), ->exists(), wp_parse_args(), get_option(), wp_required_field_indicator(), wp_required_field_message(), __(), esc_attr(), __(), esc_attr(), __(), esc_attr(), has_action(), get_option(), apply_filters(), _x(), __(), get_permalink(), apply_filters(), wp_login_url(), sprintf(), __(), get_edit_user_link(), get_permalink(), apply_filters(), wp_logout_url(), sprintf(), __(), site_url(), __(), __(), __(), __(), apply_filters(), wp_parse_args(), array_merge(), do_action(), esc_attr(), comment_form_title(), get_option(), cancel_comment_reply_link(), get_option(), esc_url(), esc_attr(), esc_attr(), printf(), do_action(), is_user_logged_in(), apply_filters(), array_keys(), array_diff(), reset(), end(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), sprintf(), apply_filters(), get_comment_id_fields(), sprintf(), apply_filters(), do_action(), do_action() |
comments_open() && !->exists() && isset($args) && !has_action() && is_user_logged_in() | 442–454 | get_post(), comments_open(), wp_get_current_commenter(), wp_get_current_user(), ->exists(), wp_parse_args(), get_option(), wp_required_field_indicator(), wp_required_field_message(), __(), esc_attr(), __(), esc_attr(), __(), esc_attr(), has_action(), apply_filters(), _x(), __(), get_permalink(), apply_filters(), wp_login_url(), sprintf(), __(), get_edit_user_link(), get_permalink(), apply_filters(), wp_logout_url(), sprintf(), __(), site_url(), __(), __(), __(), __(), apply_filters(), wp_parse_args(), array_merge(), do_action(), esc_attr(), comment_form_title(), get_option(), get_option(), is_user_logged_in(), esc_url(), esc_attr(), esc_attr(), printf(), do_action(), is_user_logged_in(), apply_filters(), do_action(), apply_filters(), array_keys(), array_diff(), reset(), end(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), sprintf(), apply_filters(), get_comment_id_fields(), sprintf(), apply_filters(), do_action(), do_action() |
comments_open() && !->exists() && isset($args) && has_action() | 442–454 | get_post(), comments_open(), wp_get_current_commenter(), wp_get_current_user(), ->exists(), wp_parse_args(), get_option(), wp_required_field_indicator(), wp_required_field_message(), __(), esc_attr(), __(), esc_attr(), __(), esc_attr(), has_action(), get_option(), apply_filters(), _x(), __(), get_permalink(), apply_filters(), wp_login_url(), sprintf(), __(), get_edit_user_link(), get_permalink(), apply_filters(), wp_logout_url(), sprintf(), __(), site_url(), __(), __(), __(), __(), apply_filters(), wp_parse_args(), array_merge(), do_action(), esc_attr(), comment_form_title(), get_option(), cancel_comment_reply_link(), get_option(), is_user_logged_in(), esc_url(), esc_attr(), esc_attr(), printf(), do_action(), is_user_logged_in(), apply_filters(), array_keys(), array_diff(), reset(), end(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), sprintf(), apply_filters(), get_comment_id_fields(), sprintf(), apply_filters(), do_action(), do_action() |
comments_open() && !->exists() && isset($args) && has_action() && !get_option() && is_user_logged_in() | 443–455 | get_post(), comments_open(), wp_get_current_commenter(), wp_get_current_user(), ->exists(), wp_parse_args(), get_option(), wp_required_field_indicator(), wp_required_field_message(), __(), esc_attr(), __(), esc_attr(), __(), esc_attr(), has_action(), get_option(), apply_filters(), _x(), __(), get_permalink(), apply_filters(), wp_login_url(), sprintf(), __(), get_edit_user_link(), get_permalink(), apply_filters(), wp_logout_url(), sprintf(), __(), site_url(), __(), __(), __(), __(), apply_filters(), wp_parse_args(), array_merge(), do_action(), esc_attr(), comment_form_title(), get_option(), get_option(), esc_url(), esc_attr(), esc_attr(), printf(), do_action(), is_user_logged_in(), apply_filters(), do_action(), apply_filters(), array_keys(), array_diff(), reset(), end(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), sprintf(), apply_filters(), get_comment_id_fields(), sprintf(), apply_filters(), do_action(), do_action() |
comments_open() && !->exists() && isset($args) && has_action() && is_user_logged_in() | 446–458 | get_post(), comments_open(), wp_get_current_commenter(), wp_get_current_user(), ->exists(), wp_parse_args(), get_option(), wp_required_field_indicator(), wp_required_field_message(), __(), esc_attr(), __(), esc_attr(), __(), esc_attr(), has_action(), get_option(), apply_filters(), _x(), __(), get_permalink(), apply_filters(), wp_login_url(), sprintf(), __(), get_edit_user_link(), get_permalink(), apply_filters(), wp_logout_url(), sprintf(), __(), site_url(), __(), __(), __(), __(), apply_filters(), wp_parse_args(), array_merge(), do_action(), esc_attr(), comment_form_title(), get_option(), get_option(), is_user_logged_in(), esc_url(), esc_attr(), esc_attr(), printf(), do_action(), is_user_logged_in(), apply_filters(), do_action(), apply_filters(), array_keys(), array_diff(), reset(), end(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), sprintf(), apply_filters(), get_comment_id_fields(), sprintf(), apply_filters(), do_action(), do_action() |
comments_open() && !->exists() && isset($args) && !has_action() && is_user_logged_in() | 448–460 | get_post(), comments_open(), wp_get_current_commenter(), wp_get_current_user(), ->exists(), wp_parse_args(), get_option(), wp_required_field_indicator(), wp_required_field_message(), __(), esc_attr(), __(), esc_attr(), __(), esc_attr(), has_action(), apply_filters(), _x(), __(), get_permalink(), apply_filters(), wp_login_url(), sprintf(), __(), get_edit_user_link(), get_permalink(), apply_filters(), wp_logout_url(), sprintf(), __(), site_url(), __(), __(), __(), __(), apply_filters(), wp_parse_args(), array_merge(), do_action(), esc_attr(), comment_form_title(), get_option(), cancel_comment_reply_link(), get_option(), esc_url(), esc_attr(), esc_attr(), printf(), do_action(), is_user_logged_in(), apply_filters(), do_action(), apply_filters(), array_keys(), array_diff(), reset(), end(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), sprintf(), apply_filters(), get_comment_id_fields(), sprintf(), apply_filters(), do_action(), do_action() |
comments_open() && !->exists() && isset($args) && !has_action() && get_option() && is_user_logged_in() | 451–463 | get_post(), comments_open(), wp_get_current_commenter(), wp_get_current_user(), ->exists(), wp_parse_args(), get_option(), wp_required_field_indicator(), wp_required_field_message(), __(), esc_attr(), __(), esc_attr(), __(), esc_attr(), has_action(), apply_filters(), _x(), __(), get_permalink(), apply_filters(), wp_login_url(), sprintf(), __(), get_edit_user_link(), get_permalink(), apply_filters(), wp_logout_url(), sprintf(), __(), site_url(), __(), __(), __(), __(), apply_filters(), wp_parse_args(), array_merge(), do_action(), esc_attr(), comment_form_title(), get_option(), cancel_comment_reply_link(), get_option(), is_user_logged_in(), esc_url(), esc_attr(), esc_attr(), printf(), do_action(), is_user_logged_in(), apply_filters(), do_action(), apply_filters(), array_keys(), array_diff(), reset(), end(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), sprintf(), apply_filters(), get_comment_id_fields(), sprintf(), apply_filters(), do_action(), do_action() |
comments_open() && !->exists() && isset($args) && has_action() && !empty($commenter) && !is_user_logged_in() | 452–471 | get_post(), comments_open(), wp_get_current_commenter(), wp_get_current_user(), ->exists(), wp_parse_args(), get_option(), wp_required_field_indicator(), wp_required_field_message(), __(), esc_attr(), __(), esc_attr(), __(), esc_attr(), has_action(), get_option(), __(), apply_filters(), _x(), __(), get_permalink(), apply_filters(), wp_login_url(), sprintf(), __(), get_edit_user_link(), get_permalink(), apply_filters(), wp_logout_url(), sprintf(), __(), site_url(), __(), __(), __(), __(), apply_filters(), wp_parse_args(), array_merge(), do_action(), esc_attr(), comment_form_title(), get_option(), get_option(), esc_url(), esc_attr(), esc_attr(), printf(), do_action(), is_user_logged_in(), apply_filters(), array_keys(), array_diff(), reset(), end(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), sprintf(), apply_filters(), get_comment_id_fields(), sprintf(), apply_filters(), do_action(), do_action() |
comments_open() && !->exists() && isset($args) && has_action() && is_user_logged_in() | 452–464 | get_post(), comments_open(), wp_get_current_commenter(), wp_get_current_user(), ->exists(), wp_parse_args(), get_option(), wp_required_field_indicator(), wp_required_field_message(), __(), esc_attr(), __(), esc_attr(), __(), esc_attr(), has_action(), get_option(), apply_filters(), _x(), __(), get_permalink(), apply_filters(), wp_login_url(), sprintf(), __(), get_edit_user_link(), get_permalink(), apply_filters(), wp_logout_url(), sprintf(), __(), site_url(), __(), __(), __(), __(), apply_filters(), wp_parse_args(), array_merge(), do_action(), esc_attr(), comment_form_title(), get_option(), cancel_comment_reply_link(), get_option(), esc_url(), esc_attr(), esc_attr(), printf(), do_action(), is_user_logged_in(), apply_filters(), do_action(), apply_filters(), array_keys(), array_diff(), reset(), end(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), sprintf(), apply_filters(), get_comment_id_fields(), sprintf(), apply_filters(), do_action(), do_action() |
comments_open() && !->exists() && isset($args) && has_action() && !empty($commenter) | 455–474 | get_post(), comments_open(), wp_get_current_commenter(), wp_get_current_user(), ->exists(), wp_parse_args(), get_option(), wp_required_field_indicator(), wp_required_field_message(), __(), esc_attr(), __(), esc_attr(), __(), esc_attr(), has_action(), get_option(), __(), apply_filters(), _x(), __(), get_permalink(), apply_filters(), wp_login_url(), sprintf(), __(), get_edit_user_link(), get_permalink(), apply_filters(), wp_logout_url(), sprintf(), __(), site_url(), __(), __(), __(), __(), apply_filters(), wp_parse_args(), array_merge(), do_action(), esc_attr(), comment_form_title(), get_option(), get_option(), is_user_logged_in(), esc_url(), esc_attr(), esc_attr(), printf(), do_action(), is_user_logged_in(), apply_filters(), array_keys(), array_diff(), reset(), end(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), sprintf(), apply_filters(), get_comment_id_fields(), sprintf(), apply_filters(), do_action(), do_action() |
comments_open() && !->exists() && isset($args) && has_action() && is_user_logged_in() | 455–467 | get_post(), comments_open(), wp_get_current_commenter(), wp_get_current_user(), ->exists(), wp_parse_args(), get_option(), wp_required_field_indicator(), wp_required_field_message(), __(), esc_attr(), __(), esc_attr(), __(), esc_attr(), has_action(), get_option(), apply_filters(), _x(), __(), get_permalink(), apply_filters(), wp_login_url(), sprintf(), __(), get_edit_user_link(), get_permalink(), apply_filters(), wp_logout_url(), sprintf(), __(), site_url(), __(), __(), __(), __(), apply_filters(), wp_parse_args(), array_merge(), do_action(), esc_attr(), comment_form_title(), get_option(), cancel_comment_reply_link(), get_option(), is_user_logged_in(), esc_url(), esc_attr(), esc_attr(), printf(), do_action(), is_user_logged_in(), apply_filters(), do_action(), apply_filters(), array_keys(), array_diff(), reset(), end(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), sprintf(), apply_filters(), get_comment_id_fields(), sprintf(), apply_filters(), do_action(), do_action() |
comments_open() && !->exists() && isset($args) && has_action() && !empty($commenter) && !is_user_logged_in() | 461–480 | get_post(), comments_open(), wp_get_current_commenter(), wp_get_current_user(), ->exists(), wp_parse_args(), get_option(), wp_required_field_indicator(), wp_required_field_message(), __(), esc_attr(), __(), esc_attr(), __(), esc_attr(), has_action(), get_option(), __(), apply_filters(), _x(), __(), get_permalink(), apply_filters(), wp_login_url(), sprintf(), __(), get_edit_user_link(), get_permalink(), apply_filters(), wp_logout_url(), sprintf(), __(), site_url(), __(), __(), __(), __(), apply_filters(), wp_parse_args(), array_merge(), do_action(), esc_attr(), comment_form_title(), get_option(), cancel_comment_reply_link(), get_option(), esc_url(), esc_attr(), esc_attr(), printf(), do_action(), is_user_logged_in(), apply_filters(), array_keys(), array_diff(), reset(), end(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), sprintf(), apply_filters(), get_comment_id_fields(), sprintf(), apply_filters(), do_action(), do_action() |
comments_open() && !->exists() && isset($args) && has_action() && get_option() && !empty($commenter) | 464–479 | get_post(), comments_open(), wp_get_current_commenter(), wp_get_current_user(), ->exists(), wp_parse_args(), get_option(), wp_required_field_indicator(), wp_required_field_message(), __(), esc_attr(), __(), esc_attr(), __(), esc_attr(), has_action(), get_option(), __(), apply_filters(), _x(), __(), get_permalink(), apply_filters(), wp_login_url(), sprintf(), __(), get_edit_user_link(), get_permalink(), apply_filters(), wp_logout_url(), sprintf(), __(), site_url(), __(), __(), __(), __(), apply_filters(), wp_parse_args(), array_merge(), do_action(), esc_attr(), comment_form_title(), get_option(), cancel_comment_reply_link(), get_option(), is_user_logged_in(), esc_url(), esc_attr(), esc_attr(), printf(), do_action(), is_user_logged_in(), apply_filters(), array_keys(), array_diff(), reset(), end(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), sprintf(), apply_filters(), get_comment_id_fields(), sprintf(), apply_filters(), do_action(), do_action() |
comments_open() && !->exists() && isset($args) && has_action() && !empty($commenter) && is_user_logged_in() | 465–484 | get_post(), comments_open(), wp_get_current_commenter(), wp_get_current_user(), ->exists(), wp_parse_args(), get_option(), wp_required_field_indicator(), wp_required_field_message(), __(), esc_attr(), __(), esc_attr(), __(), esc_attr(), has_action(), get_option(), __(), apply_filters(), _x(), __(), get_permalink(), apply_filters(), wp_login_url(), sprintf(), __(), get_edit_user_link(), get_permalink(), apply_filters(), wp_logout_url(), sprintf(), __(), site_url(), __(), __(), __(), __(), apply_filters(), wp_parse_args(), array_merge(), do_action(), esc_attr(), comment_form_title(), get_option(), get_option(), esc_url(), esc_attr(), esc_attr(), printf(), do_action(), is_user_logged_in(), apply_filters(), do_action(), apply_filters(), array_keys(), array_diff(), reset(), end(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), sprintf(), apply_filters(), get_comment_id_fields(), sprintf(), apply_filters(), do_action(), do_action() |
comments_open() && !->exists() && isset($args) && has_action() && !empty($commenter) && is_user_logged_in() | 468–487 | get_post(), comments_open(), wp_get_current_commenter(), wp_get_current_user(), ->exists(), wp_parse_args(), get_option(), wp_required_field_indicator(), wp_required_field_message(), __(), esc_attr(), __(), esc_attr(), __(), esc_attr(), has_action(), get_option(), __(), apply_filters(), _x(), __(), get_permalink(), apply_filters(), wp_login_url(), sprintf(), __(), get_edit_user_link(), get_permalink(), apply_filters(), wp_logout_url(), sprintf(), __(), site_url(), __(), __(), __(), __(), apply_filters(), wp_parse_args(), array_merge(), do_action(), esc_attr(), comment_form_title(), get_option(), get_option(), is_user_logged_in(), esc_url(), esc_attr(), esc_attr(), printf(), do_action(), is_user_logged_in(), apply_filters(), do_action(), apply_filters(), array_keys(), array_diff(), reset(), end(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), sprintf(), apply_filters(), get_comment_id_fields(), sprintf(), apply_filters(), do_action(), do_action() |
comments_open() && !->exists() && isset($args) && has_action() && !empty($commenter) && is_user_logged_in() | 474–492 | get_post(), comments_open(), wp_get_current_commenter(), wp_get_current_user(), ->exists(), wp_parse_args(), get_option(), wp_required_field_indicator(), wp_required_field_message(), __(), esc_attr(), __(), esc_attr(), __(), esc_attr(), has_action(), get_option(), __(), apply_filters(), _x(), __(), get_permalink(), apply_filters(), wp_login_url(), sprintf(), __(), get_edit_user_link(), get_permalink(), apply_filters(), wp_logout_url(), sprintf(), __(), site_url(), __(), __(), __(), __(), apply_filters(), wp_parse_args(), array_merge(), do_action(), esc_attr(), comment_form_title(), get_option(), cancel_comment_reply_link(), get_option(), esc_url(), esc_attr(), esc_attr(), printf(), do_action(), is_user_logged_in(), apply_filters(), do_action(), apply_filters(), array_keys(), array_diff(), reset(), end(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), sprintf(), apply_filters(), get_comment_id_fields(), sprintf(), apply_filters(), do_action(), do_action() |
comments_open() && !->exists() && isset($args) && has_action() && get_option() && !empty($commenter) && is_user_logged_in() | 477–492 | get_post(), comments_open(), wp_get_current_commenter(), wp_get_current_user(), ->exists(), wp_parse_args(), get_option(), wp_required_field_indicator(), wp_required_field_message(), __(), esc_attr(), __(), esc_attr(), __(), esc_attr(), has_action(), get_option(), __(), apply_filters(), _x(), __(), get_permalink(), apply_filters(), wp_login_url(), sprintf(), __(), get_edit_user_link(), get_permalink(), apply_filters(), wp_logout_url(), sprintf(), __(), site_url(), __(), __(), __(), __(), apply_filters(), wp_parse_args(), array_merge(), do_action(), esc_attr(), comment_form_title(), get_option(), cancel_comment_reply_link(), get_option(), is_user_logged_in(), esc_url(), esc_attr(), esc_attr(), printf(), do_action(), is_user_logged_in(), apply_filters(), do_action(), apply_filters(), array_keys(), array_diff(), reset(), end(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), sprintf(), apply_filters(), get_comment_id_fields(), sprintf(), apply_filters(), do_action(), do_action() |
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 | 576 | 11–495 | 32 | 3 more instructions than PHP 8.5 |
| 8.5 | 573 | 11–492 | 32 | |
| 8.4 | 573 | 11–492 | 32 | 15 fewer instructions than PHP 8.3 |
| 8.3 | 588 | 11–507 | 32 | |
| 8.2 | 588 | 11–507 | 32 | |
| 8.1 | 588 | 11–507 | 32 | 2 fewer instructions than PHP 7.4 |
| 7.4 | 590 | 11–508 | 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 · 19
19 hooks fire while comment_form() runs, in this order:
- do_action( comment_form_comments_closed )actionline 2507 (+13 into the body)
Fires after the comment form if comments are closed.
- apply_filters( comment_form_default_fields )filterline 2605 (+111 into the body)
Filters the default comment form fields.
- apply_filters( the_permalink )filterline 2624 (+130 into the body)
Filters the display of the permalink for the current post.
- apply_filters( the_permalink )filterline 2635 (+141 into the body)
Filters the display of the permalink for the current post.
- apply_filters( comment_form_defaults )filterline 2679 (+185 into the body)
Filters the comment form default arguments.
- do_action( comment_form_must_log_in_after )actionline 2724 (+230 into the body)
Fires after the HTML-formatted 'must log in after' message in the comment form.
- do_action( comment_form_top )actionline 2741 (+247 into the body)
Fires at the top of the comment form, inside the form tag.
- apply_filters( comment_form_logged_in )filterline 2757 (+263 into the body)
Filters the 'logged in' message for the comment form for display.
- do_action( comment_form_logged_in_after )actionline 2769 (+275 into the body)
Fires after the is_user_logged_in() check in the comment form.
- apply_filters( comment_form_fields )filterline 2787 (+293 into the body)
Filters the comment form fields, including the textarea.
- apply_filters( comment_form_field_comment )filterline 2807 (+313 into the body)
Filters the content of the comment textarea field for display.
- do_action( comment_form_before_fields )actionline 2819 (+325 into the body)
Fires before the comment fields in the comment form, excluding the textarea.
- apply_filters( comment_form_field_{$name} )filterline 2840 (+346 into the body)
Filters a comment form field for display.
- do_action( comment_form_after_fields )actionline 2848 (+354 into the body)
Fires after the comment fields in the comment form, excluding the textarea.
- apply_filters( comment_form_submit_button )filterline 2869 (+375 into the body)
Filters the submit button for the comment form to display.
- apply_filters( comment_form_submit_field )filterline 2888 (+394 into the body)
Filters the submit field for the comment form to display.
- do_action( comment_form )actionline 2897 (+403 into the body)
Fires at the bottom of the comment form, inside the closing form tag.
Uses · 26
- get_post()Retrieves post data given a post ID or post object.
- comments_open()Determines whether the current post is open for comments.
- do_action()Calls the callback functions that have been added to an action hook.
- wp_get_current_commenter()Gets current commenter's name, email, and URL.
- wp_get_current_user()Retrieves the current user object.
- wp_parse_args()Merges user defined arguments into defaults array.
- current_theme_supports()Checks a theme's support for a given feature.
- get_option()Retrieves an option value based on an option name.
- wp_required_field_indicator()Assigns a visual indicator for required form fields.
- wp_required_field_message()Creates a message to explain required form fields.
- __()Retrieves the translation of $text.
- esc_attr()Escaping for HTML attributes.
Show all 26
- has_action()Checks if any action has been registered for a hook.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- _x()Retrieves translated string with gettext context.
- wp_login_url()Retrieves the login URL.
- get_permalink()Retrieves the full permalink for the current post or post ID.
- get_edit_user_link()Retrieves the edit user link.
- wp_logout_url()Retrieves the logout URL.
- site_url()Retrieves the URL for the current site where WordPress application files (e.g. wp-blog-header.php or the wp-admin/ folder) are accessible.
- str_contains()Polyfill for `str_contains()` function added in PHP 8.0.
- comment_form_title()Displays text based on comment reply status.
- cancel_comment_reply_link()Displays HTML content for cancel comment reply link.
- is_user_logged_in()Determines whether the current visitor is a logged in user.
- esc_url()Checks and cleans a URL.
- get_comment_id_fields()Retrieves hidden input HTML for replying to comments.
Used by · 2
- render_block_core_post_comments_form()Renders the `core/post-comments-form` block on the server.
- twentynineteen_comment_form()Displays the comment form.
Source code
function comment_form( $args = array(), $post = null ) { $post = get_post( $post ); // Exit the function if the post is invalid or comments are closed. if ( ! $post || ! comments_open( $post ) ) { /** * Fires after the comment form if comments are closed. * * For backward compatibility, this action also fires if comment_form() * is called with an invalid post object or ID. * * @since 3.0.0 */ do_action( 'comment_form_comments_closed' ); return; } $post_id = $post->ID; $commenter = wp_get_current_commenter(); $user = wp_get_current_user(); $user_identity = $user->exists() ? $user->display_name : ''; $args = wp_parse_args( $args ); if ( ! isset( $args['format'] ) ) { $args['format'] = current_theme_supports( 'html5', 'comment-form' ) ? 'html5' : 'xhtml'; } $req = get_option( 'require_name_email' ); $html5 = 'html5' === $args['format']; // Define attributes in HTML5 or XHTML syntax. $required_attribute = ( $html5 ? ' required' : ' required="required"' ); $checked_attribute = ( $html5 ? ' checked' : ' checked="checked"' ); // Identify required fields visually and create a message about the indicator. $required_indicator = ' ' . wp_required_field_indicator(); $required_text = ' ' . wp_required_field_message(); $fields = array( 'author' => sprintf( '<p class="comment-form-author">%s %s</p>', sprintf( '<label for="author">%s%s</label>', __( 'Name' ), ( $req ? $required_indicator : '' ) ), sprintf( '<input id="author" name="author" type="text" value="%s" size="30" maxlength="245" autocomplete="name"%s />', esc_attr( $commenter['comment_author'] ), ( $req ? $required_attribute : '' ) ) ), 'email' => sprintf( '<p class="comment-form-email">%s %s</p>', sprintf( '<label for="email">%s%s</label>', __( 'Email' ), ( $req ? $required_indicator : '' ) ), sprintf( '<input id="email" name="email" %s value="%s" size="30" maxlength="100" aria-describedby="email-notes" autocomplete="email"%s />', ( $html5 ? 'type="email"' : 'type="text"' ), esc_attr( $commenter['comment_author_email'] ), ( $req ? $required_attribute : '' ) ) ), 'url' => sprintf( '<p class="comment-form-url">%s %s</p>', sprintf( '<label for="url">%s</label>', __( 'Website' ) ), sprintf( '<input id="url" name="url" %s value="%s" size="30" maxlength="200" autocomplete="url" />', ( $html5 ? 'type="url"' : 'type="text"' ), esc_attr( $commenter['comment_author_url'] ) ) ), );Changelog
Introduced in 6.8.2. 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/comment-template.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.