Advertisement
TheDeadMedic

WP Comment Form Function

Jun 10th, 2011
2,866
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.91 KB | None | 0 0
  1. /**
  2.  * @see comment_form()
  3.  */
  4. function my_comment_form( $args = array(), $post_id = null ) {
  5.     global $user_identity, $id;
  6.  
  7.     if ( null === $post_id )
  8.         $post_id = $id;
  9.     else
  10.         $id = $post_id;
  11.  
  12.     $commenter = wp_get_current_commenter();
  13.  
  14.     $req = get_option( 'require_name_email' );
  15.     $aria_req = ( $req ? " aria-required='true'" : '' );
  16.     $fields =  array(
  17.         'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .
  18.                     '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
  19.         'email'  => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .
  20.                     '<input id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',
  21.         'url'    => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label>' .
  22.                     '<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>',
  23.     );
  24.  
  25.     $required_text = sprintf( ' ' . __('Required fields are marked %s'), '<span class="required">*</span>' );
  26.     $defaults = array(
  27.         'fields'               => apply_filters( 'comment_form_default_fields', $fields ),
  28.         '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>',
  29.         '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>',
  30.         '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>',
  31.         'comment_notes_before' => '<p class="comment-notes">' . __( 'Your email address will not be published.' ) . ( $req ? $required_text : '' ) . '</p>',
  32.         'comment_notes_after'  => '<p class="form-allowed-tags">' . sprintf( __( 'You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: %s' ), ' <code>' . allowed_tags() . '</code>' ) . '</p>',
  33.         'id_form'              => 'commentform',
  34.         'id_submit'            => 'submit',
  35.         'class_submit'         => 'submit',
  36.         'title_reply'          => __( 'Leave a Reply' ),
  37.         'title_reply_to'       => __( 'Leave a Reply to %s' ),
  38.         'cancel_reply_link'    => __( 'Cancel reply' ),
  39.         'label_submit'         => __( 'Post Comment' ),
  40.     );
  41.  
  42.     $args = wp_parse_args( $args, apply_filters( 'comment_form_defaults', $defaults ) );
  43.  
  44.     ?>
  45.         <?php if ( comments_open() ) : ?>
  46.             <?php do_action( 'comment_form_before' ); ?>
  47.             <div id="respond">
  48.                 <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>
  49.                 <?php if ( get_option( 'comment_registration' ) && !is_user_logged_in() ) : ?>
  50.                     <?php echo $args['must_log_in']; ?>
  51.                     <?php do_action( 'comment_form_must_log_in_after' ); ?>
  52.                 <?php else : ?>
  53.                     <form action="<?php echo site_url( '/wp-comments-post.php' ); ?>" method="post" id="<?php echo esc_attr( $args['id_form'] ); ?>">
  54.                         <?php do_action( 'comment_form_top' ); ?>
  55.                         <?php if ( is_user_logged_in() ) : ?>
  56.                             <?php echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity ); ?>
  57.                             <?php do_action( 'comment_form_logged_in_after', $commenter, $user_identity ); ?>
  58.                         <?php else : ?>
  59.                             <?php echo $args['comment_notes_before']; ?>
  60.                             <?php
  61.                             do_action( 'comment_form_before_fields' );
  62.                             foreach ( (array) $args['fields'] as $name => $field ) {
  63.                                 echo apply_filters( "comment_form_field_{$name}", $field ) . "\n";
  64.                             }
  65.                             do_action( 'comment_form_after_fields' );
  66.                             ?>
  67.                         <?php endif; ?>
  68.                         <?php echo apply_filters( 'comment_form_field_comment', $args['comment_field'] ); ?>
  69.                         <?php echo $args['comment_notes_after']; ?>
  70.                         <p class="form-submit">
  71.                             <input name="submit" type="submit" id="<?php echo esc_attr( $args['id_submit'] ); ?>" class="<?php echo esc_attr( $args['class_submit'] ); ?>" value="<?php echo esc_attr( $args['label_submit'] ); ?>" />
  72.                             <?php comment_id_fields(); ?>
  73.                         </p>
  74.                         <?php do_action( 'comment_form', $post_id ); ?>
  75.                     </form>
  76.                 <?php endif; ?>
  77.             </div><!-- #respond -->
  78.             <?php do_action( 'comment_form_after' ); ?>
  79.         <?php else : ?>
  80.             <?php do_action( 'comment_form_comments_closed' ); ?>
  81.         <?php endif; ?>
  82.     <?php
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement