Posted By

alik on 01/25/11


Tagged

form php wordpress comment commentform


Versions (?)

WP Comment Form Override Function


 / Published in: PHP
 

  1. function comment_form_new( $args = array(), $post_id = null ) {
  2. global $user_identity, $id;
  3.  
  4. if ( null === $post_id )
  5. $post_id = $id;
  6. else
  7. $id = $post_id;
  8.  
  9. $commenter = wp_get_current_commenter();
  10.  
  11. $req = get_option( 'require_name_email' );
  12. $aria_req = ( $req ? " aria-required='true'" : '' );
  13. $fields = array(
  14. 'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .
  15. '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
  16. 'email' => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .
  17. '<input id="email" name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',
  18. 'url' => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label>' .
  19. '<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>',
  20. );
  21.  
  22. $required_text = sprintf( ' ' . __('Required fields are marked %s'), '<span class="required"><a>*</a></span>' );
  23. $defaults = array(
  24. 'fields' => apply_filters( 'comment_form_default_fields', $fields ),
  25. 'comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>',
  26. 'must_log_in' => '<p class="must-log-in">' . 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>',
  27. 'logged_in_as' => '<p class="logged-in-as">' . sprintf( __( 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>' ), admin_url( 'profile.php' ), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
  28. 'comment_notes_before' => '<p class="comment-notes">' . __( 'Your email address will not be published.' ) . ( $req ? $required_text : '' ) . '</p>',
  29.  
  30. 'id_form' => 'commentform',
  31. 'id_submit' => 'submit',
  32. 'title_reply' => __( 'Leave <a>a Comment</a>' ),
  33. 'title_reply_to' => __( 'Leave a Reply to %s' ),
  34. 'cancel_reply_link' => __( 'Cancel reply' ),
  35. 'label_submit' => __( 'Send Comment' ),
  36. );
  37.  
  38. $args = wp_parse_args( $args, apply_filters( 'comment_form_defaults', $defaults ) );
  39.  
  40. ?>
  41. <?php if ( comments_open() ) : ?>
  42. <?php do_action( 'comment_form_before' ); ?>
  43. <div id="respond">
  44. <h3 id="reply-title"><?php comment_form_title( $args['title_reply'], $args['title_reply_to'] ); ?> <small><?php cancel_comment_reply_link( $args['cancel_reply_link'] ); ?></small></h3>
  45. <?php if ( get_option( 'comment_registration' ) && !is_user_logged_in() ) : ?>
  46. <?php echo $args['must_log_in']; ?>
  47. <?php do_action( 'comment_form_must_log_in_after' ); ?>
  48. <?php else : ?>
  49. <form action="<?php echo site_url( '/wp-comments-post.php' ); ?>" method="post" id="<?php echo esc_attr( $args['id_form'] ); ?>">
  50. <?php do_action( 'comment_form_top' ); ?>
  51. <?php if ( is_user_logged_in() ) : ?>
  52. <?php echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity ); ?>
  53. <?php do_action( 'comment_form_logged_in_after', $commenter, $user_identity ); ?>
  54. <?php else : ?>
  55. <?php echo $args['comment_notes_before']; ?>
  56. <?php
  57. do_action( 'comment_form_before_fields' );
  58. foreach ( (array) $args['fields'] as $name => $field ) {
  59. echo apply_filters( "comment_form_field_{$name}", $field ) . "\n";
  60. }
  61. do_action( 'comment_form_after_fields' );
  62. ?>
  63. <?php endif; ?>
  64. <?php echo apply_filters( 'comment_form_field_comment', $args['comment_field'] ); ?>
  65. <?php echo $args['comment_notes_after']; ?>
  66. <p class="form-submit">
  67. <input name="submit" type="submit" id="<?php echo esc_attr( $args['id_submit'] ); ?>" value="<?php echo esc_attr( $args['label_submit'] ); ?>" />
  68. <?php comment_id_fields(); ?>
  69. </p>
  70. <?php do_action( 'comment_form', $post_id ); ?>
  71. </form>
  72. <?php endif; ?>
  73. </div><!-- #respond -->
  74. <?php do_action( 'comment_form_after' ); ?>
  75. <?php else : ?>
  76. <?php do_action( 'comment_form_comments_closed' ); ?>
  77. <?php endif; ?>
  78. <?php
  79. }

Report this snippet  

You need to login to post a comment.