@@ -99,6 +99,7 @@ public function __construct( $register_hooks = true ) {
9999 add_action ( 'wp_ajax_tutor_create_lesson_comment ' , array ( $ this , 'tutor_single_course_lesson_load_more ' ) );
100100 add_action ( 'wp_ajax_tutor_delete_lesson_comment ' , array ( $ this , 'ajax_delete_lesson_comment ' ) );
101101 add_action ( 'wp_ajax_tutor_reply_lesson_comment ' , array ( $ this , 'reply_lesson_comment ' ) );
102+ add_action ( 'wp_ajax_tutor_load_lesson_comments ' , array ( $ this , 'load_lesson_comments ' ) );
102103
103104 // Add lesson title as nav item & render single content on the learning area.
104105 add_action ( "tutor_learning_area_nav_item_ {$ this ->post_type }" , array ( $ this , 'render_nav_item ' ), 10 , 2 );
@@ -123,8 +124,11 @@ public function tutor_single_course_lesson_load_more() {
123124 self ::create_comment ( $ comment_data );
124125 do_action ( 'tutor_new_comment_added ' , $ comment_data );
125126 }
127+
128+ $ is_legacy_learning_mode = tutor_utils ()->get_option ( 'is_legacy_learning_mode ' );
129+
126130 ob_start ();
127- tutor_load_template ( 'single.lesson.comment ' );
131+ tutor_load_template ( $ is_legacy_learning_mode ? 'single.lesson.comment ' : ' learning-area.lesson.comment-list ' );
128132 $ html = ob_get_clean ();
129133 wp_send_json_success ( array ( 'html ' => $ html ) );
130134 }
@@ -588,31 +592,39 @@ public function reply_lesson_comment() {
588592 $ reply = get_comment ( $ comment_id );
589593 do_action ( 'tutor_reply_lesson_comment_thread ' , $ comment_id , $ comment_data );
590594
591- ob_start ();
592- ?>
593- <div class="tutor-comments-list tutor-child-comment tutor-mt-32" id="lesson-comment-<?php echo esc_attr ( $ reply ->comment_ID ); ?> ">
594- <div class="comment-avatar">
595- <img src="<?php echo esc_url ( get_avatar_url ( $ reply ->user_id ) ); ?> " alt="">
596- </div>
597- <div class="tutor-single-comment">
598- <div class="tutor-actual-comment tutor-mb-12">
599- <div class="tutor-comment-author">
600- <span class="tutor-fs-6 tutor-fw-bold">
601- <?php echo esc_html ( $ reply ->comment_author ); ?>
602- </span>
603- <span class="tutor-fs-7 tutor-ml-0 tutor-ml-sm-10">
604- <?php echo esc_html ( human_time_diff ( strtotime ( $ reply ->comment_date ), tutor_time () ) . __ ( ' ago ' , 'tutor ' ) ); ?>
605- </span>
606- </div>
607- <div class="tutor-comment-text tutor-fs-6 tutor-mt-4">
608- <?php echo esc_html ( $ reply ->comment_content ); ?>
595+ $ is_legacy_learning_mode = tutor_utils ()->get_option ( 'is_legacy_learning_mode ' );
596+ if ( $ is_legacy_learning_mode ) {
597+ ob_start ();
598+ ?>
599+ <div class="tutor-comments-list tutor-child-comment tutor-mt-32" id="lesson-comment-<?php echo esc_attr ( $ reply ->comment_ID ); ?> ">
600+ <div class="comment-avatar">
601+ <img src="<?php echo esc_url ( get_avatar_url ( $ reply ->user_id ) ); ?> " alt="">
602+ </div>
603+ <div class="tutor-single-comment">
604+ <div class="tutor-actual-comment tutor-mb-12">
605+ <div class="tutor-comment-author">
606+ <span class="tutor-fs-6 tutor-fw-bold">
607+ <?php echo esc_html ( $ reply ->comment_author ); ?>
608+ </span>
609+ <span class="tutor-fs-7 tutor-ml-0 tutor-ml-sm-10">
610+ <?php echo esc_html ( human_time_diff ( strtotime ( $ reply ->comment_date ), tutor_time () ) . __ ( ' ago ' , 'tutor ' ) ); ?>
611+ </span>
612+ </div>
613+ <div class="tutor-comment-text tutor-fs-6 tutor-mt-4">
614+ <?php echo esc_html ( $ reply ->comment_content ); ?>
615+ </div>
609616 </div>
610617 </div>
611618 </div>
612- </div>
613- <?php
614- $ html = ob_get_clean ();
615- wp_send_json_success ( array ( 'html ' => $ html ) );
619+ <?php
620+ $ html = ob_get_clean ();
621+ wp_send_json_success ( array ( 'html ' => $ html ) );
622+ } else {
623+ ob_start ();
624+ tutor_load_template ( 'learning-area.lesson.comment-list ' );
625+ $ html = ob_get_clean ();
626+ wp_send_json_success ( array ( 'html ' => $ html ) );
627+ }
616628 }
617629
618630 /**
@@ -835,4 +847,54 @@ public function render_single_content( $lesson ): void {
835847 )
836848 );
837849 }
850+
851+ /**
852+ * Load lesson comments
853+ *
854+ * @since 4.0.0
855+ *
856+ * @return void
857+ */
858+ public function load_lesson_comments () {
859+ $ lesson_id = Input::post ( 'lesson_id ' ?? 0 );
860+ $ current_page = Input::post ( 'current_page ' , '1 ' );
861+
862+ $ item_per_page = tutor_utils ()->get_option ( 'pagination_per_page ' , 10 );
863+
864+ $ comment_list = self ::get_comments (
865+ array (
866+ 'post_id ' => $ lesson_id ,
867+ 'parent ' => 0 ,
868+ 'paged ' => $ current_page ,
869+ 'number ' => $ item_per_page ,
870+ )
871+ );
872+
873+ // Get total comment count to determine if there are more pages.
874+ $ total_comments = self ::get_comments (
875+ array (
876+ 'post_id ' => $ lesson_id ,
877+ 'parent ' => 0 ,
878+ 'count ' => true ,
879+ )
880+ );
881+
882+ ob_start ();
883+ tutor_load_template (
884+ 'learning-area.lesson.comment-items ' ,
885+ compact ( 'comment_list ' , 'lesson_id ' )
886+ );
887+ $ html = ob_get_clean ();
888+
889+ // Calculate if there are more items beyond current page.
890+ $ items_loaded = $ current_page * $ item_per_page ;
891+ $ has_more = $ items_loaded < $ total_comments ;
892+
893+ wp_send_json_success (
894+ array (
895+ 'html ' => $ html ,
896+ 'has_more ' => $ has_more ,
897+ )
898+ );
899+ }
838900}
0 commit comments