cyberdev

Untitled

Jul 11th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.39 KB | None | 0 0
  1. <?php
  2. /**
  3.  * The Template Part for displaying Comments.
  4.  *
  5.  * @license For the full license information, please view the Licensing folder
  6.  * that was distributed with this source code.
  7.  *
  8.  * @package snax
  9.  * @subpackage Theme
  10.  */
  11.  
  12. // Prevent direct script access.
  13. if ( ! defined( 'ABSPATH' ) ) {
  14.     die( 'No direct script access allowed' );
  15. }
  16.  
  17. if ( post_password_required() ) {
  18.     return;
  19. }
  20. ?>
  21. <?php if ( get_comments_number() || comments_open() ) : ?>
  22.  
  23. <?php if ( comments_open() ) {
  24.     $post_id = $post->ID ;
  25.         if ( ! comments_open( $post_id ) ) {
  26.         return;
  27.     }
  28.     $max_lenght                 = apply_filters( 'snax_item_comment_max_length', 250 );
  29.     $action                     = site_url( '/wp-comments-post.php' );
  30.     $disable_guest_comments     = get_option( 'comment_registration' );
  31.     $disable_anonymous_comments = get_option( 'require_name_email' );
  32.  
  33.     $comments_permalink = apply_filters( 'the_permalink', get_permalink( $post_id ) ) . '/#respond';
  34.     $login_permalink = wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) );
  35.     $must_login_message         = sprintf(
  36.         __( 'You must be <a href="%s">logged in</a> to post a comment.' ),
  37.         $login_permalink
  38.     );
  39.     $must_give_data_message     = sprintf(
  40.         __( 'Anonymous comments are not allowed, please post with the <a href="%s">full comment form</a>' ),
  41.         $comments_permalink
  42.     );
  43.  
  44.     if ( ! is_user_logged_in() && $disable_guest_comments ) {
  45.         echo '<p class="must-log-in">' . wp_kses_post( $must_login_message ) . '</p>';
  46.         return;
  47.     }
  48.     if ( ! is_user_logged_in() && $disable_anonymous_comments ) {
  49.         echo '<p class="must-log-in">' . wp_kses_post( $must_give_data_message ) . '</p>';
  50.         return;
  51.     }
  52.     ?>
  53.     <div id="respond" class="comment-respond">
  54.     <small>
  55.         <?php cancel_comment_reply_link( __( 'Cancel reply' ) ); ?>
  56.     </small>
  57.     <form action="<?php echo esc_url( $action ); ?>" method="post" id="commentform" class="comment-form" novalidate="">
  58.     <?php do_action( 'comment_form_top' );?>
  59.     <textarea id="comment" placeholder="<?php echo esc_attr(_x( 'Write a comment&hellip;', 'snax' )) ?>*" maxlength="<?php echo esc_attr( $max_lenght ); ?>" name="comment" cols="45" rows="1" aria-required="true"></textarea>
  60.     <p class="form-submit"><input name="submit" type="submit" id="submit" class="submit" value="<?php echo esc_attr__( 'Post', 'snax' ) ?>" disabled="disabled">
  61.     <?php comment_id_fields( $post_id );?>
  62.     </p>
  63.     <?php wp_comment_form_unfiltered_html_nonce();?>
  64.     </form>
  65.     </div>
  66.     <?php
  67. } ?>
  68.  
  69.     <section class="comments-area" itemscope itemtype="http://schema.org/UserComments">
  70.  
  71.                 <?php
  72.                 $per_page = apply_filters( 'snax_item_on_list_comments_per_page',3 );
  73.                 $args = array(
  74.                         'post_id'   => $post->ID,
  75.                     );
  76.                 $comments = get_comments( $args );
  77.                 $top_level_comments_count = 0;
  78.                 foreach ( $comments as $comment ) {
  79.                     if ( ! $comment->comment_parent ) {
  80.                         $top_level_comments_count += 1;
  81.                     }
  82.                 }
  83.                 if ( $top_level_comments_count > $per_page ) {
  84.                     add_filter( 'snax_display_see_more_for_comment', '__return_true' );
  85.                 } else {
  86.                     add_filter( 'snax_display_see_more_for_comment', '__return_false' );
  87.                 }
  88.                 ?>
  89.  
  90.             <ol class="comment-list" data-snax-top-level-comments="<?php echo esc_attr( $top_level_comments_count ); ?>">
  91.                 <?php
  92.                 wp_list_comments( array(
  93.                     'type'              => 'comment',
  94.                     'per_page'          => $per_page,
  95.                 ), $comments );
  96.                 ?>
  97.             </ol>
  98.  
  99.     </section><!-- #comments -->
  100. <?php endif;
Add Comment
Please, Sign In to add comment