Advertisement
imranmodel32

Wordpress Comment form with Bootstrap 3

Nov 21st, 2014
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.36 KB | None | 0 0
  1. // modify comment form fields
  2.  
  3. add_filter( 'comment_form_default_fields', 'salospa_bootstrap3_comment_form_fields' );
  4. function salospa_bootstrap3_comment_form_fields( $fields ) {
  5.     $commenter  = wp_get_current_commenter();
  6.     $req        = get_option( 'require_name_email' );
  7.     $aria_req   = ( $req ? " aria-required='true'" : '' );
  8.     $html5      = current_theme_supports( 'html5', 'comment-form' ) ? 1 : 0;
  9.    
  10.     $fields   =  array(
  11.         'warp-start'=> '<div class="row">',
  12.       'author'    => '<div class="col-md-6"><div class="form-group comment-form-author">' . '<label for="author">' . __( 'Name', 'salospa' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .'<input class="form-control" id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></div></div>',
  13.       'email'     => '<div class="col-md-6"><div class="form-group comment-form-email"><label for="email">' . __( 'Email', 'salospa' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .'<input class="form-control" id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></div></div>',
  14.       'url'       => '<div class="col-md-12"><div class="form-group comment-form-url"><label for="url">' . __( 'Website', 'salospa' ) . '</label> ' .'<input class="form-control" id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></div></div>',                    
  15.     );
  16.    
  17.     return $fields;
  18. }
  19.  
  20.  
  21. // modify the comment form
  22.  
  23. add_filter( 'comment_form_defaults', 'salospa_bootstrap3_comment_form' );
  24. function salospa_bootstrap3_comment_form( $args ) {
  25.     $args['comment_field']        = '<div class="col-md-12"><div class="form-group comment-form-comment"><label for="comment">' . __( 'Comment', 'salospa' ) . '</label> <textarea class="form-control" id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></div></div>';
  26.     $args['comment_notes_after']    = '<div class="col-md-12"><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></div>';
  27.  
  28.     return $args;
  29. }
  30.  
  31.  
  32. add_action('comment_form', 'salospa_bootstrap3_comment_button' );
  33. function salospa_bootstrap3_comment_button() {
  34.     echo '<div class="col-md-12 column"><button class="btn btn-lg ar_btn_md ar_tarn" type="submit"><i class="fa fa-comments-o"></i>' . __( 'Submit', 'salospa' ) . '</button></div></div>';
  35. }
  36.  
  37. /************* COMMENT LAYOUT *********************/
  38.  
  39. // Comment Layout
  40. function salospa_comments( $comment, $args, $depth ) {
  41.    $GLOBALS['comment'] = $comment; ?>
  42.     <li <?php comment_class(); ?>>
  43.         <article id="comment-<?php comment_ID(); ?>" class="clearfix comment-container">
  44.       <div class="media">
  45.             <div class="author-thumb media-left">
  46.                 <?php $bgauthemail = get_comment_author_email();?>
  47.                 <?php echo get_avatar( $comment, 50 ); ?>
  48.             </div>
  49.         <div class="comment-content media-body">
  50.           <div class="comment-meta">
  51.             <?php printf(__( '<cite class="fn">%s</cite>', 'salospa' ), get_comment_author_link()) ?> <?php _e( '<span class="says">says:</span>','salospa' );?>
  52.             <time datetime="<?php echo comment_time('Y-m-j'); ?>"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php comment_time(__( 'F jS, Y', 'salospa' )); ?> </a></time>
  53.           </div><!-- comment-meta -->
  54.           <?php edit_comment_link(__( '(Edit)', 'salospa' ),'  ','') ?>
  55.                 <?php if ($comment->comment_approved == '0') : ?>
  56.                     <div class="alert alert-info">
  57.                         <p><?php _e( 'Your comment is awaiting moderation.', 'salospa' ) ?></p>
  58.                     </div>
  59.                 <?php endif; ?>
  60.                 <section class="comment_content clearfix">
  61.                     <?php comment_text() ?>
  62.                 </section>
  63.         </div> <!-- END comment-content -->
  64.       </div><!-- media -->
  65.       <div class="reply"><?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?></div><!-- reply comment-reply-link btn ar_btn_md ar_tarn -->
  66.         </article>
  67.     <?php // </li> is added by WordPress automatically ?>
  68. <?php
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement