| 1414 | /** |
| 1415 | * Outputs a complete commenting form for use within a template. |
| 1416 | * Most strings and form fields may be controlled through the $args array passed |
| 1417 | * into the function, while you may also choose to use the comments_form_default_fields |
| 1418 | * filter to modify the array of default fields if you'd just like to add a new |
| 1419 | * one or remove a single field. All fields are also individually passed through |
| 1420 | * a filter of the form comments_form_field_$name where $name is the key used |
| 1421 | * in the array of fields. |
| 1422 | * |
| 1423 | * @since x.x |
| 1424 | * @param array $args Options for strings, fields etc in the form |
| 1425 | * @param mixed $post_id Post ID to generate the form for, uses the current post if null |
| 1426 | * @return void |
| 1427 | */ |
| 1428 | function comment_form( $args = array(), $post_id = null ) { |
| 1429 | global $user_identity, $id; |
| 1430 | |
| 1431 | if ( null === $post_id ) |
| 1432 | $post_id = $id; |
| 1433 | else |
| 1434 | $id = $post_id; |
| 1435 | |
| 1436 | $commenter = wp_get_current_commenter(); |
| 1437 | |
| 1438 | $req = get_option( 'require_name_email' ); |
| 1439 | $aria_req = ( $req ? " aria-required='true'" : '' ); |
| 1440 | $req_str = ( $req ? __( ' (required)' ) : '' ); |
| 1441 | $defaults = array( 'fields' => apply_filters( 'comment_form_default_fields', array( 'author' => '<p><input type="text" name="author" id="author" value="' . esc_attr( $commenter['comment_author'] ) . '" size="22" tabindex="1"' . $aria_req . ' /> <label for="author"><small>' . __( 'Name' ) . $req_str . '</small></label></p>', |
| 1442 | 'email' => '<p><input type="text" name="email" id="email" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="22" tabindex="2"' . $aria_req . ' /> <label for="email"><small>' . __( 'Mail (will not be published)' ) . $req_str . '</small></label></p>', |
| 1443 | 'url' => '<p><input type="text" name="url" id="url" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="22" tabindex="3" /> <label for="url"><small>' . __( 'Website' ) . '</small></label></p>' ) ), |
| 1444 | 'comment_field' => '<p><textarea name="comment" id="comment" cols="58" rows="10" tabindex="4"></textarea></p>', |
| 1445 | 'must_log_in' => '<p>' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>', |
| 1446 | 'logged_in_as' => '<p>' . sprintf( __( 'Logged in as <a href="%s">%s</a>. <a href="%s" title="Log out of this account">Log out »</a></p>' ), admin_url( 'profile.php' ), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ), |
| 1447 | 'id_form' => 'commentform', |
| 1448 | 'id_submit' => 'submit', |
| 1449 | 'title_reply' => __( 'Leave a Reply' ), |
| 1450 | 'title_reply_to' => __( 'Leave a Reply to %s'), |
| 1451 | 'cancel_reply_link' => '', |
| 1452 | 'label_submit' => __( 'Submit Comment' ), |
| 1453 | ); |
| 1454 | $args = wp_parse_args( $args, apply_filters( 'comment_form_defaults', $defaults ) ); |
| 1455 | |
| 1456 | ?> |
| 1457 | <?php if ( comments_open() ) : ?> |
| 1458 | <?php do_action( 'comment_form_before' ); ?> |
| 1459 | <div id="respond"> |
| 1460 | <h3><?php comment_form_title( $args['title_reply'], $args['title_reply_to'] ); ?></h3> |
| 1461 | <div class="cancel-comment-reply"> |
| 1462 | <small><?php cancel_comment_reply_link( $args['cancel_comment_reply_link'] ); ?></small> |
| 1463 | </div> |
| 1464 | <?php if ( get_option( 'comment_registration' ) && !is_user_logged_in() ) : ?> |
| 1465 | <?php echo $args['must_log_in']; ?> |
| 1466 | <?php do_action( 'comment_form_must_log_in_after' ); ?> |
| 1467 | <?php else : ?> |
| 1468 | <form action="<?php echo site_url( '/wp-comments-post.php' ); ?>" method="post" id="<?php echo esc_attr( $args['id_form'] ); ?>"> |
| 1469 | <?php do_action( 'comment_form_top' ); ?> |
| 1470 | <?php if ( is_user_logged_in() ) : ?> |
| 1471 | <?php echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity ); ?> |
| 1472 | <?php do_action( 'comment_form_logged_in_after', $commenter, $user_identity ); ?> |
| 1473 | <?php else : ?> |
| 1474 | <?php |
| 1475 | do_action( 'comment_form_before_fields' ); |
| 1476 | foreach ( (array) $args['fields'] as $name => $field ) { |
| 1477 | echo apply_filters( "comment_form_field_{$name}", $field ) . "\n"; |
| 1478 | } |
| 1479 | do_action( 'comment_form_after_fields' ); |
| 1480 | ?> |
| 1481 | <?php endif; ?> |
| 1482 | <?php echo apply_filters( 'comment_form_field_comment', $args['comment_field'] ); ?> |
| 1483 | <p> |
| 1484 | <input name="submit" type="submit" id="<?php echo esc_attr( $args['id_submit'] ); ?>" tabindex="<?php echo ( count( $args['fields'] ) + 2 ); ?>" value="<?php echo esc_attr( $args['label_submit'] ); ?>" /> |
| 1485 | <?php comment_id_fields(); ?> |
| 1486 | </p> |
| 1487 | <?php do_action( 'comments_form', $post_id ); ?> |
| 1488 | </form> |
| 1489 | <?php endif; ?> |
| 1490 | </div> |
| 1491 | <?php do_action( 'comment_form_after' ); ?> |
| 1492 | <?php else : ?> |
| 1493 | <?php do_action( 'comment_form_comments_closed' ); ?> |
| 1494 | <?php endif; ?> |
| 1495 | <?php |
| 1496 | } |
| 1497 | |