Guest User

Untitled

a guest
Dec 13th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.87 KB | None | 0 0
  1. /**
  2.  * Outputs a complete commenting form for use within a template.
  3.  * Most strings and form fields may be controlled through the $args array passed
  4.  * into the function, while you may also choose to use the comment_form_default_fields
  5.  * filter to modify the array of default fields if you'd just like to add a new
  6.  * one or remove a single field. All fields are also individually passed through
  7.  * a filter of the form comment_form_field_$name where $name is the key used
  8.  * in the array of fields.
  9.  *
  10.  * @since 3.0.0
  11.  * @param array $args Options for strings, fields etc in the form
  12.  * @param mixed $post_id Post ID to generate the form for, uses the current post if null
  13.  * @return void
  14.  */
  15. function comment_form( $args = array(), $post_id = null ) {
  16.     global $id;
  17.  
  18.     if ( null === $post_id )
  19.         $post_id = $id;
  20.     else
  21.         $id = $post_id;
  22.  
  23.     $commenter = wp_get_current_commenter();
  24.     $user = wp_get_current_user();
  25.     $user_identity = $user->exists() ? $user->display_name : '';
  26.  
  27.     $req = get_option( 'require_name_email' );
  28.     $aria_req = ( $req ? " aria-required='true'" : '' );
  29.     $fields =  array(
  30.         'author' => '<p class="comment-form-author">' . '<label for="author">' . __( '' ) . '</label> ' . ( $req ? '<span class="required"></span>' : '' ) .
  31.                     '<input id="author" name="author" placeholder="Имя*" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
  32.                    
  33.         'email'  => '<p class="comment-form-email"><label for="email">' . __( '' ) . '</label> ' . ( $req ? '<span class="required"></span>' : '' ) .
  34.                     '<input id="email" name="email" placeholder="Email*" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',
  35.                    
  36.         'url'    => '<p class="comment-form-url"><label for="url">' . __( '' ) . '</label>' .
  37.                     '<input id="url" name="url" placeholder="Website" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>',
  38.                    
  39.         'age'    => '<p class="comment-form-age"><label for="age">' . __( '' ) . '</label>' . ( $req ? '<span class="required"></span>' : '' ) .
  40.                     '<input id="age" name="age" placeholder="Возраст*" type="text" value="' . esc_attr( $commenter['comment_author_age'] ) . '" size="30" /></p>',
  41.     );
  42.  
  43.     $required_text = sprintf( ' ' . __(' '), '<span class="required">*</span>' );
  44.     $defaults = array(
  45.         'fields'               => apply_filters( 'comment_form_default_fields', $fields ),
  46.         'comment_field'        => '<p class="comment-form-comment"><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true" placeholder="Ваш комментарий..."></textarea></p>',
  47.         '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>',
  48.         '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>',
  49.         'comment_notes_before' => '<p class="comment-notes">' . __( '' ) . ( $req ? $required_text : '' ) . '</p>',
  50.         '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>',
  51.         'id_form'              => '',
  52.         'id_submit'            => 'submit',
  53.         'title_reply'          => __( 'Leave a Reply' ),
  54.         'title_reply_to'       => __( 'Leave a Reply to %s' ),
  55.         'cancel_reply_link'    => __( 'Cancel reply' ),
  56.         'label_submit'         => __( 'Post Comment' ),
  57.     );
  58.  
  59.     $args = wp_parse_args( $args, apply_filters( 'comment_form_defaults', $defaults ) );
  60.    
  61.     ?>
  62.         <?php if ( comments_open( $post_id ) ) : ?>
  63.             <?php do_action( 'comment_form_before' ); ?>
  64.             <div id="respond">
  65.                 <h3 id="reply-title"><?php comment_form_title( $args['<div style="height: 50px;"></div>'], $args['title_reply_to'] ); ?> <small><?php cancel_comment_reply_link( $args['cancel_reply_link'] ); ?></small></h3>
  66.                 <?php if ( get_option( 'comment_registration' ) && !is_user_logged_in() ) : ?>
  67.                     <?php echo $args['must_log_in']; ?>
  68.                     <?php do_action( 'comment_form_must_log_in_after' ); ?>
  69.                 <?php else : ?>
  70.                     <form action="<?php echo site_url( '/wp-comments-post.php' ); ?>" method="post" id="<?php echo esc_attr( $args['id_form'] ); ?>">
  71.                         <?php do_action( 'comment_form_top' ); ?>
  72.                         <?php if ( is_user_logged_in() ) : ?>
  73.                             <?php echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity ); ?>
  74.                             <?php do_action( 'comment_form_logged_in_after', $commenter, $user_identity ); ?>
  75.                         <?php else : ?>
  76.                             <?php echo $args['comment_notes_before']; ?>
  77.                             <?php
  78.                             do_action( 'comment_form_before_fields' );
  79.                             foreach ( (array) $args['fields'] as $name => $field ) {
  80.                                 echo apply_filters( "comment_form_field_{$name}", $field ) . "\n";
  81.                             }
  82.                             do_action( 'comment_form_after_fields' );
  83.                             ?>
  84.                         <?php endif; ?>
  85.                         <?php echo apply_filters( 'comment_form_field_comment', $args['comment_field'] ); ?>
  86.                         <!--<?php echo $args['comment_notes_after']; ?>-->
  87.                         <p class="form-submit">
  88.                             <input name="submit" type="submit" id="<?php echo esc_attr( $args['id_submit'] ); ?>" value="<?php echo esc_attr( $args['label_submit'] ); ?>" />
  89.                             <?php comment_id_fields( $post_id ); ?>
  90.                         </p>
  91.                         <?php do_action( 'comment_form', $post_id ); ?>
  92.                     </form>
  93.                 <?php endif; ?>
  94.             </div><!-- #respond -->
  95.             <?php do_action( 'comment_form_after' ); ?>
  96.         <?php else : ?>
  97.             <?php do_action( 'comment_form_comments_closed' ); ?>
  98.         <?php endif; ?>
  99.     <?php
  100. }
Add Comment
Please, Sign In to add comment