| 1399 | /** |
| 1400 | * Outputs a complete commenting form for use within a template. |
| 1401 | * Most strings and form fields may be controlled through the $args array passed |
| 1402 | * into the function, while you may also choose to use the comments_form_default_fields |
| 1403 | * filter to modify the array of default fields if you'd just like to add a new |
| 1404 | * one or remove a single field. All fields are also individually passed through |
| 1405 | * a filter of the form comments_form_field_$name where $name is the key used |
| 1406 | * in the array of fields. |
| 1407 | * |
| 1408 | * @since x.x |
| 1409 | * @param array $args Options for strings, fields etc in the form |
| 1410 | * @param mixed $post_id Post ID to generate the form for, uses the current post if null |
| 1411 | * @return void |
| 1412 | */ |
| 1413 | function comment_form( $args = array(), $post_id = null ) { |
| 1414 | global $req, $commenter, $comment_author, $comment_author_email, $comment_author_url, $user_identity, $id; |
| 1415 | |
| 1416 | if ( null === $post_id ) |
| 1417 | $post_id = $id; |
| 1418 | else |
| 1419 | $id = $post_id; |
| 1420 | |
| 1421 | $aria_req = ( $req ? " aria-required='true'" : '' ); |
| 1422 | $req_str = ( $req ? __( ' (required)' ) : '' ); |
| 1423 | $defaults = array( 'fields' => apply_filters( 'comment_form_default_fields', array( 'author' => '<p><input type="text" name="author" id="author" value="' . esc_attr( $comment_author ) . '" size="22" tabindex="1"' . $aria_req . ' /> <label for="author"><small>' . __( 'Name' ) . $req_str . '</small></label></p>', |
| 1424 | 'email' => '<p><input type="text" name="email" id="email" value="' . esc_attr( $comment_author_email ) . '" size="22" tabindex="2"' . $aria_req . ' /> <label for="email"><small>' . __( 'Mail (will not be published)' ) . $req_str . '</small></label></p>', |
| 1425 | 'url' => '<p><input type="text" name="url" id="url" value="' . esc_attr( $comment_author_url ) . '" size="22" tabindex="3" /> <label for="url"><small>' . __( 'Website' ) . '</small></label></p>' ) ), |
| 1426 | 'comment_form_comment_field' => '<p><textarea name="comment" id="comment" cols="58" rows="10" tabindex="4"></textarea></p>', |
| 1427 | 'must_log_in' => '<p>' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), wp_login_url( get_permalink( $post_id ) ) ) . '</p>', |
| 1428 | '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( get_permalink( $post_id ) ) ), |
| 1429 | ); |
| 1430 | $args = wp_parse_args( $args, $defaults ); |
| 1431 | |
| 1432 | do_action( 'comment_form_before' ); |
| 1433 | ?> |
| 1434 | <?php if ( comments_open() ) : ?> |
| 1435 | <div id="respond"> |
| 1436 | <h3><?php comment_form_title( apply_filters( 'comment_form_title', __( 'Leave a Reply' ) ), apply_filters( 'comment_form_title_reply_to', __( 'Leave a Reply to %s' ) ) ); ?></h3> |
| 1437 | <div class="cancel-comment-reply"> |
| 1438 | <small><?php cancel_comment_reply_link( apply_filters( 'comment_form_cancel_reply', '' ) ); ?></small> |
| 1439 | </div> |
| 1440 | <?php if ( get_option( 'comment_registration' ) && !is_user_logged_in() ) : ?> |
| 1441 | <?php echo apply_filters( 'comment_form_must_log_in', $args['must_log_in'] ); ?> |
| 1442 | <?php do_action( 'comment_form_must_log_in_after' ); ?> |
| 1443 | <?php else : ?> |
| 1444 | <form action="<?php echo get_option( 'siteurl' ); ?>/wp-comments-post.php" method="post" id="commentform"> |
| 1445 | <?php if ( is_user_logged_in() ) : ?> |
| 1446 | <?php echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity ); ?> |
| 1447 | <?php do_action( 'comment_form_logged_in_after', $commenter, $user_identity ); ?> |
| 1448 | <?php else : ?> |
| 1449 | <?php |
| 1450 | do_action( 'comment_form_before_fields' ); |
| 1451 | foreach ( $args['fields'] as $name => $field ) { |
| 1452 | echo apply_filters( "comment_form_field_{$name}", $field ) . "\n"; |
| 1453 | } |
| 1454 | do_action( 'comment_form_after_fields' ); |
| 1455 | ?> |
| 1456 | <?php endif; ?> |
| 1457 | <?php echo apply_filters( 'comment_form_field_comment', $args['comment_form_comment_field'] ); ?> |
| 1458 | <p> |
| 1459 | <input name="submit" type="submit" id="submit" tabindex="<?php echo ( count( $args['fields'] ) + 2 ); ?>" value="<?php echo apply_filters( 'comment_form_submit', __( 'Submit Comment' ) ); ?>" /> |
| 1460 | <?php comment_id_fields(); ?> |
| 1461 | </p> |
| 1462 | <?php do_action( 'comments_form', $post_id ); ?> |
| 1463 | </form> |
| 1464 | <?php endif; ?> |
| 1465 | </div> |
| 1466 | <?php endif; ?> |
| 1467 | <?php |
| 1468 | do_action( 'comment_form_after' ); |
| 1469 | } |
| 1470 | |