comment_form() – Outputs a complete commenting form for use within a template.

You appear to be a bot. Output may be restricted

Description

Outputs a complete commenting form for use within a template.

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_form_field_$name where $name is the key used in the array of fields.

Usage

comment_form( $args, $post );

Parameters

$args
( array ) optional – { Optional. Default arguments and form fields to override.
$fields
( array ) optional – { Default comment fields, filterable by default via the comment_form_default_fields hook.
$author
( string ) optional – Comment author field HTML.
$email
( string ) optional – Comment author email field HTML.
$url
( string ) optional – Comment author URL field HTML.
$cookies
( string ) optional – Comment cookie opt-in field HTML. }
$comment_field
( string ) optional – The comment textarea field HTML.
$must_log_in
( string ) optional – HTML element for a 'must be logged in to comment' message.
$logged_in_as
( string ) optional – The HTML for the 'logged in as [user]' message, the Edit profile link, and the Log out link.
$comment_notes_before
( string ) optional – HTML element for a message displayed before the comment fields if the user is not logged in. Default 'Your email address will not be published.'.
$comment_notes_after
( string ) optional – HTML element for a message displayed after the textarea field.
$action
( string ) optional – The comment form element action attribute. Default '/wp-comments-post.php'.
$id_form
( string ) optional – The comment form element id attribute. Default 'commentform'.
$id_submit
( string ) optional – The comment submit element id attribute. Default 'submit'.
$class_container
( string ) optional – The comment form container class attribute. Default 'comment-respond'.
$class_form
( string ) optional – The comment form element class attribute. Default 'comment-form'.
$class_submit
( string ) optional – The comment submit element class attribute. Default 'submit'.
$name_submit
( string ) optional – The comment submit element name attribute. Default 'submit'.
$title_reply
( string ) optional – The translatable 'reply' button label. Default 'Leave a Reply'.
$title_reply_to
( string ) optional – The translatable 'reply-to' button label. Default 'Leave a Reply to %s', where %s is the author of the comment being replied to.
$title_reply_before
( string ) optional – HTML displayed before the comment form title. Default: '<h3 id="reply-title" class="comment-reply-title">'.
$title_reply_after
( string ) optional – HTML displayed after the comment form title. Default: '</h3>'.
$cancel_reply_before
( string ) optional – HTML displayed before the cancel reply link.
$cancel_reply_after
( string ) optional – HTML displayed after the cancel reply link.
$cancel_reply_link
( string ) optional – The translatable 'cancel reply' button label. Default 'Cancel reply'.
$label_submit
( string ) optional – The translatable 'submit' button label. Default 'Post a comment'.
$submit_button
( string ) optional – HTML format for the Submit button. Default: '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />'.
$submit_field
( string ) optional – HTML format for the markup surrounding the Submit button and comment hidden fields. Default: '<p class="form-submit">%1$s %2$s</p>', where %1$s is the submit button markup and %2$s is the comment hidden fields.
$format
( string ) optional – The comment form format. Default 'xhtml'. Accepts 'xhtml', 'html5'. }
$post
( int|WP_Post ) optional – Optional. Post ID or WP_Post object to generate the form for. Default current post.

Returns

void

Source

File name: wordpress/wp-includes/comment-template.php
Lines:

201 to 300 of 416
   */
  do_action( 'comment_form_before' );
  ?>
	<div id="respond" class="<?php echo esc_attr( $args['class_container'] ); ?>">
		<?php
    echo $args['title_reply_before'];

    comment_form_title( $args['title_reply'], $args['title_reply_to'], true, $post_id );

    if ( get_option( 'thread_comments' ) ) {
      echo $args['cancel_reply_before'];

      cancel_comment_reply_link( $args['cancel_reply_link'] );

      echo $args['cancel_reply_after'];
    }

    echo $args['title_reply_after'];

    if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) :

      echo $args['must_log_in'];
      
/**
 * Fires after the HTML-formatted 'must log in after' message in the comment form.
 *
 * @since 3.0.0
 */
      do_action( 'comment_form_must_log_in_after' );

    else :

      printf(
        '<form action="%s" method="post" id="%s" class="%s"%s>',
        esc_url( $args['action'] ),
        esc_attr( $args['id_form'] ),
        esc_attr( $args['class_form'] ),
        ( $html5 ? ' novalidate' : '' )
      );

      
/**
 * Fires at the top of the comment form, inside the form tag.
 *
 * @since 3.0.0
 */
      do_action( 'comment_form_top' );

      if ( is_user_logged_in() ) :

        
/**
 * Filters the 'logged in' message for the comment form for display.
 *
 * @since 3.0.0
 *
 * @param string $args_logged_in The HTML for the 'logged in as [user]' message,
 *                               the Edit profile link, and the Log out link.
 * @param array  $commenter      An array containing the comment author's
 *                               username, email, and URL.
 * @param string $user_identity  If the commenter is a registered user,
 *                               the display name, blank otherwise.
 */
        echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity );

        
/**
 * Fires after the is_user_logged_in() check in the comment form.
 *
 * @since 3.0.0
 *
 * @param array  $commenter     An array containing the comment author's
 *                              username, email, and URL.
 * @param string $user_identity If the commenter is a registered user,
 *                              the display name, blank otherwise.
 */
        do_action( 'comment_form_logged_in_after', $commenter, $user_identity );

      else :

        echo $args['comment_notes_before'];

      endif;

      // Prepare an array of all fields, including the textarea.
      $comment_fields = array( 'comment' => $args['comment_field'] ) + (array) $args['fields'];

      
/**
 * Filters the comment form fields, including the textarea.
 *
 * @since 4.4.0
 *
 * @param array $comment_fields The comment fields.
 */
      $comment_fields = apply_filters( 'comment_form_fields', $comment_fields );

      // Get an array of field names, excluding the textarea.
      $comment_field_keys = array_diff( array_keys( $comment_fields ), array( 'comment' ) );

      // Get the first and the last field name, excluding the textarea.
      $first_field = reset( $comment_field_keys );
      $last_field  = end( $comment_field_keys );

      foreach ( $comment_fields as $name => $field ) {
 

 View on GitHub View on Trac