wppaste
WordPress

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
Source
wp-includes/comment-template.php:2493
Outputs a complete commenting form for use within a template.

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 5.5.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$argsarrayoptional
Default arguments and form fields to override.Default: array()
  • $fieldsarray

    { Default comment fields, filterable by default via the 'comment_form_default_fields' hook.
  • $authorstring

    Comment author field HTML.
  • $emailstring

    Comment author email field HTML.
  • $urlstring

    Comment author URL field HTML.
  • $cookiesstring

    Comment cookie opt-in field HTML. } @type string $comment_field The comment textarea field HTML.
  • $must_log_instring

    HTML element for a 'must be logged in to comment' message.
  • $logged_in_asstring

    The 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_afterstring

    HTML element for a message displayed after the textarea field.
  • $actionstringdefault: '/wp-comments-post.php'

    The comment form element action attribute.
  • $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 to

    The 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_beforestring

    HTML displayed before the cancel reply link.
  • $cancel_reply_afterstring

    HTML 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_fieldstring

    HTML 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

Reaches the database via get_post().

Scaling
Scales with input

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

Instructions
11–489

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

Plugin surface
18 hooks

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.

Called by
2

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

What it touches

  • querycontent queryget_post()called directly
  • hookthird-party callbacksdo_action()called directly
  • optionoption read or writeget_option()called directly
  • cacheobject cachewp_cache_get()one call below comment_form()
  • serializeserialisationmaybe_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.

WhenInstructionsCalls it makes
always11get_post(), do_action()
comments_open() && !->exists() && isset($args) && !has_action() && !is_user_logged_in()316–326get_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()320–330get_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()325–335get_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()329–339get_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()342–359get_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()351–364get_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()423–435get_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()426–438get_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()427–439get_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()430–442get_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()432–444get_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 489 instructions
comments_open() && !->exists() && isset($args) && !has_action() && get_option()435–447get_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()436–448get_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()436–448get_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()439–451get_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()439–451get_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()440–452get_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()443–455get_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()445–457get_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()448–460get_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()449–468get_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()449–461get_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)452–471get_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()452–464get_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()458–477get_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)461–476get_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()462–481get_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()465–484get_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()471–489get_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()474–489get_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

PHPCompiledExecutedBranchesNotes
8.6-dev57111–492313 more instructions than PHP 8.5
8.556811–48931
8.456811–4893115 fewer instructions than PHP 8.3
8.358311–50431
8.258311–50431
8.158311–504312 fewer instructions than PHP 7.4
7.458511–50531

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:

  1. do_action( comment_form_comments_closed )actionline 2506 (+13 into the body)

    Fires after the comment form if comments are closed.

  2. apply_filters( comment_form_default_fields )filterline 2602 (+109 into the body)

    Filters the default comment form fields.

  3. apply_filters( the_permalink )filterline 2621 (+128 into the body)

    Filters the display of the permalink for the current post.

  4. apply_filters( the_permalink )filterline 2632 (+139 into the body)

    Filters the display of the permalink for the current post.

  5. apply_filters( comment_form_defaults )filterline 2675 (+182 into the body)

    Filters the comment form default arguments.

  6. do_action( comment_form_before )actionline 2694 (+201 into the body)

    Fires before the comment form.

  7. do_action( comment_form_must_log_in_after )actionline 2720 (+227 into the body)

    Fires after the HTML-formatted 'must log in after' message in the comment form.

  8. do_action( comment_form_top )actionline 2737 (+244 into the body)

    Fires at the top of the comment form, inside the form tag.

  9. apply_filters( comment_form_logged_in )filterline 2753 (+260 into the body)

    Filters the 'logged in' message for the comment form for display.

  10. do_action( comment_form_logged_in_after )actionline 2765 (+272 into the body)

    Fires after the is_user_logged_in() check in the comment form.

  11. apply_filters( comment_form_fields )filterline 2783 (+290 into the body)

    Filters the comment form fields, including the textarea.

  12. apply_filters( comment_form_field_comment )filterline 2803 (+310 into the body)

    Filters the content of the comment textarea field for display.

  13. do_action( comment_form_before_fields )actionline 2815 (+322 into the body)

    Fires before the comment fields in the comment form, excluding the textarea.

  14. apply_filters( comment_form_field_{$name} )filterline 2836 (+343 into the body)

    Filters a comment form field for display.

  15. do_action( comment_form_after_fields )actionline 2844 (+351 into the body)

    Fires after the comment fields in the comment form, excluding the textarea.

  16. apply_filters( comment_form_submit_button )filterline 2865 (+372 into the body)

    Filters the submit button for the comment form to display.

  17. apply_filters( comment_form_submit_field )filterline 2884 (+391 into the body)

    Filters the submit field for the comment form to display.

  18. do_action( comment_form )actionline 2893 (+400 into the body)

    Fires at the bottom of the comment form, inside the closing form tag.

  19. do_action( comment_form_after )actionline 2907 (+414 into the body)

    Fires after the comment form.

Uses · 26

Show all 26

Used by · 2

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 5.5.0. Unchanged from 6.7.7 through 7.1.0.

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

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

5.5.0
Introduced the 'class_container' argument.from the docblock
4.9.6
Introduced the 'cookies' default comment field.from the docblock
4.6.0
Introduced the 'action' argument.from the docblock
4.5.0
The 'author', 'email', and 'url' form fields are limited to 245, 100, and 200 characters, respectively.from the docblock
4.4.0
Introduced the 'class_form', 'title_reply_before', 'title_reply_after', 'cancel_reply_before', and 'cancel_reply_after' arguments.from the docblock
4.2.0
Introduced the 'submit_button' and 'submit_fields' arguments.from the docblock
4.1.0
Introduced the 'class_submit' argument.from the docblock
3.0.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.7.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.