PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 2.7.6
Tutor LMS – eLearning and online course solution v2.7.6
3.9.14 3.9.13 3.9.12 3.9.11 trunk 1.0.0 1.0.0-alpha 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.2.0 1.2.1 1.2.11 1.2.12 1.2.13 1.2.20 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.1 1.8.10 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.14 1.9.15 1.9.16 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.10 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.10 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.3.0 2.4.0 2.5.0 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.1.0 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / classes / Lesson.php
tutor / classes Last commit date
Addons.php 2 years ago Admin.php 2 years ago Ajax.php 1 year ago Announcements.php 1 year ago Assets.php 2 years ago Backend_Page_Trait.php 3 years ago Course.php 1 year ago Course_Embed.php 3 years ago Course_Filter.php 1 year ago Course_List.php 1 year ago Course_Settings_Tabs.php 3 years ago Course_Widget.php 3 years ago Custom_Validation.php 3 years ago Dashboard.php 3 years ago FormHandler.php 2 years ago Frontend.php 2 years ago Gutenberg.php 3 years ago Input.php 3 years ago Instructor.php 2 years ago Instructors_List.php 1 year ago Lesson.php 1 year ago Options_V2.php 1 year ago Permalink.php 2 years ago Post_types.php 2 years ago Private_Course_Access.php 3 years ago Q_And_A.php 1 year ago Question_Answers_List.php 3 years ago Quiz.php 1 year ago Quiz_Attempts_List.php 1 year ago RestAPI.php 2 years ago Reviews.php 3 years ago Rewrite_Rules.php 2 years ago Shortcode.php 1 year ago Student.php 2 years ago Students_List.php 3 years ago Taxonomies.php 3 years ago Template.php 2 years ago Theme_Compatibility.php 3 years ago Tools.php 3 years ago Tools_V2.php 2 years ago Tutor.php 2 years ago TutorEDD.php 2 years ago Tutor_Base.php 2 years ago Tutor_Setup.php 2 years ago Upgrader.php 2 years ago User.php 2 years ago Utils.php 1 year ago Video_Stream.php 3 years ago WhatsNew.php 2 years ago Withdraw.php 2 years ago Withdraw_Requests_List.php 3 years ago WooCommerce.php 1 year ago
Lesson.php
648 lines
1 <?php
2 /**
3 * Manage Lesson
4 *
5 * @package Tutor
6 * @author Themeum <support@themeum.com>
7 * @link https://themeum.com
8 * @since 1.0.0
9 */
10
11 namespace TUTOR;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 use Tutor\Models\LessonModel;
18
19 /**
20 * Lesson class
21 *
22 * @since 1.0.0
23 */
24 class Lesson extends Tutor_Base {
25
26 /**
27 * Register hooks
28 *
29 * @since 1.0.0
30 *
31 * @return void
32 */
33 public function __construct() {
34 parent::__construct();
35
36 add_action( 'add_meta_boxes', array( $this, 'register_meta_box' ) );
37 add_action( 'save_post_' . $this->lesson_post_type, array( $this, 'save_lesson_meta' ) );
38
39 add_action( 'wp_ajax_tutor_load_edit_lesson_modal', array( $this, 'tutor_load_edit_lesson_modal' ) );
40 add_action( 'wp_ajax_tutor_modal_create_or_update_lesson', array( $this, 'tutor_modal_create_or_update_lesson' ) );
41 add_action( 'wp_ajax_tutor_delete_lesson_by_id', array( $this, 'tutor_delete_lesson_by_id' ) );
42
43 add_filter( 'get_sample_permalink', array( $this, 'change_lesson_permalink' ), 10, 2 );
44
45 /**
46 * Add Column
47 */
48 add_filter( "manage_{$this->lesson_post_type}_posts_columns", array( $this, 'add_column' ), 10, 1 );
49 add_action( "manage_{$this->lesson_post_type}_posts_custom_column", array( $this, 'custom_lesson_column' ), 10, 2 );
50
51 /**
52 * Frontend Action
53 */
54 add_action( 'template_redirect', array( $this, 'mark_lesson_complete' ) );
55
56 add_action( 'wp_ajax_tutor_render_lesson_content', array( $this, 'tutor_render_lesson_content' ) );
57
58 /**
59 * For public course access
60 */
61 add_action( 'wp_ajax_nopriv_tutor_render_lesson_content', array( $this, 'tutor_render_lesson_content' ) );
62
63 /**
64 * Autoplay next video
65 *
66 * @since 1.4.9
67 */
68 add_action( 'wp_ajax_autoload_next_course_content', array( $this, 'autoload_next_course_content' ) );
69
70 /**
71 * Load next course item after click complete button
72 *
73 * @since 1.5.3
74 */
75 add_action( 'tutor_lesson_completed_after', array( $this, 'tutor_lesson_completed_after' ), 999 );
76
77 /**
78 * Lesson comment & reply ajax handler
79 *
80 * @since 2.0.0
81 */
82 add_action( 'wp_ajax_tutor_single_course_lesson_load_more', array( $this, 'tutor_single_course_lesson_load_more' ) );
83 add_action( 'wp_ajax_tutor_create_lesson_comment', array( $this, 'tutor_single_course_lesson_load_more' ) );
84 add_action( 'wp_ajax_tutor_reply_lesson_comment', array( $this, 'reply_lesson_comment' ) );
85 }
86
87 /**
88 * Manage load more & comment create
89 *
90 * @since 2.0.6
91 * @return void send wp json data
92 */
93 public function tutor_single_course_lesson_load_more() {
94 tutor_utils()->checking_nonce();
95 $comment = Input::post( 'comment', '', Input::TYPE_KSES_POST );
96 if ( 'tutor_create_lesson_comment' === Input::post( 'action' ) && strlen( $comment ) > 0 ) {
97 $comment_data = array(
98 'comment_content' => $comment,
99 'comment_post_ID' => Input::post( 'comment_post_ID', 0, Input::TYPE_INT ),
100 'comment_parent' => Input::post( 'comment_parent', 0, Input::TYPE_INT ),
101 );
102 self::create_comment( $comment_data );
103 do_action( 'tutor_new_comment_added', $comment_data );
104 }
105 ob_start();
106 tutor_load_template( 'single.lesson.comment' );
107 $html = ob_get_clean();
108 wp_send_json_success( array( 'html' => $html ) );
109 }
110
111 /**
112 * Registering metabox
113 *
114 * @since 1.0.0
115 * @return void
116 */
117 public function register_meta_box() {
118 $lesson_post_type = $this->lesson_post_type;
119
120 tutor_meta_box_wrapper( 'tutor-course-select', __( 'Select Course', 'tutor' ), array( $this, 'lesson_metabox' ), $lesson_post_type, 'advanced', 'default', 'tutor-admin-post-meta' );
121
122 tutor_meta_box_wrapper( 'tutor-lesson-videos', __( 'Lesson Video', 'tutor' ), array( $this, 'lesson_video_metabox' ), $lesson_post_type, 'advanced', 'default', 'tutor-admin-post-meta' );
123
124 tutor_meta_box_wrapper( 'tutor-lesson-attachments', __( 'Attachments', 'tutor' ), array( $this, 'lesson_attachments_metabox' ), $lesson_post_type, 'advanced', 'default', 'tutor-admin-post-meta' );
125 }
126
127 /**
128 * Lesson metabox
129 *
130 * @since 1.0.0
131 *
132 * @return void
133 */
134 public function lesson_metabox() {
135 include tutor()->path . 'views/metabox/lesson-metabox.php';
136 }
137
138 /**
139 * Video metabox
140 *
141 * @since 1.0.0
142 *
143 * @return void
144 */
145 public function lesson_video_metabox() {
146 include tutor()->path . 'views/metabox/video-metabox.php';
147 }
148
149 /**
150 * Attachment metabox
151 *
152 * @since 1.0.0
153 *
154 * @return void
155 */
156 public function lesson_attachments_metabox() {
157 include tutor()->path . 'views/metabox/lesson-attachments-metabox.php';
158 }
159
160 /**
161 * Saving lesson meta and assets
162 *
163 * @since 1.0.0
164 *
165 * @param integer $post_ID post ID.
166 * @return void
167 */
168 public function save_lesson_meta( $post_ID ) {
169 $video_source = sanitize_text_field( tutor_utils()->array_get( 'video.source', $_POST ) ); //phpcs:ignore
170 if ( '-1' === $video_source ) {
171 delete_post_meta( $post_ID, '_video' );
172 } elseif ( $video_source ) {
173
174 // Sanitize data through helper method.
175 $video = Input::sanitize_array(
176 $_POST['video'] ?? array(), //phpcs:ignore
177 array(
178 'source_external_url' => 'esc_url',
179 'source_embedded' => 'wp_kses_post',
180 ),
181 true
182 );
183 update_post_meta( $post_ID, '_video', $video );
184 }
185
186 // Attachments.
187 $attachments = array();
188 // phpcs:disable WordPress.Security.NonceVerification.Missing
189 if ( ! empty( $_POST['tutor_attachments'] ) ) {
190 //phpcs:ignore -- data sanitized through helper method.
191 $attachments = tutor_utils()->sanitize_array( wp_unslash( $_POST['tutor_attachments'] ) );
192 $attachments = array_unique( $attachments );
193 }
194
195 /**
196 * If !empty attachment then update meta else
197 * delete meta key to prevent empty data in db
198 *
199 * @since 1.8.9
200 */
201 if ( ! empty( $attachments ) ) {
202 update_post_meta( $post_ID, '_tutor_attachments', $attachments );
203 } else {
204 delete_post_meta( $post_ID, '_tutor_attachments' );
205 }
206
207 }
208
209 /**
210 * Load edit lesson modal
211 *
212 * @since 1.0.0
213 *
214 * @return void
215 */
216 public function tutor_load_edit_lesson_modal() {
217 tutor_utils()->checking_nonce();
218
219 $lesson_id = Input::post( 'lesson_id', 0, Input::TYPE_INT );
220 $topic_id = Input::post( 'topic_id', 0, Input::TYPE_INT );
221
222 if ( ! tutor_utils()->can_user_manage( 'topic', $topic_id ) ) {
223 wp_send_json_error( array( 'message' => __( 'Access Denied', 'tutor' ) ) );
224 }
225
226 if ( 0 !== $lesson_id ) {
227 if ( ! tutor_utils()->can_user_manage( 'lesson', $lesson_id ) ) {
228 wp_send_json_error( array( 'message' => tutor_utils()->error_message() ) );
229 }
230 }
231
232 /**
233 * If Lesson Not Exists, provide dummy
234 */
235 $post_arr = array(
236 'ID' => 0,
237 'post_content' => '',
238 'post_type' => $this->lesson_post_type,
239 'post_title' => __( 'Draft Lesson', 'tutor' ),
240 'post_status' => 'publish',
241 'post_author' => get_current_user_id(),
242 'post_parent' => $topic_id,
243 );
244
245 $post = $lesson_id ? get_post( $lesson_id ) : (object) $post_arr;
246
247 ob_start();
248 include tutor()->path . 'views/modal/edit-lesson.php';
249 $output = ob_get_clean();
250
251 wp_send_json_success( array( 'output' => $output ) );
252 }
253
254 /**
255 * Load lesson modal for create or update lesson
256 *
257 * @since 1.0.0
258 * @since 1.5.1 updated
259 *
260 * @return void
261 */
262 public function tutor_modal_create_or_update_lesson() {
263 tutor_utils()->checking_nonce();
264
265 global $wpdb;
266
267 /**
268 * Allow iframe inside lesson content to support
269 * embed video & other stuff
270 *
271 * @since 2.1.6
272 */
273 add_filter( 'wp_kses_allowed_html', Input::class . '::allow_iframe', 10, 2 );
274
275 $lesson_id = Input::post( 'lesson_id', 0, Input::TYPE_INT );
276 $topic_id = Input::post( 'current_topic_id', 0, Input::TYPE_INT );
277 $current_topic_id = $topic_id;
278 $course_id = tutor_utils()->get_course_id_by( 'topic', $topic_id );
279
280 if ( ! tutor_utils()->can_user_manage( 'topic', $topic_id ) ) {
281 wp_send_json_error( array( 'message' => __( 'Access Denied', 'tutor' ) ) );
282 }
283
284 $title = Input::post( 'lesson_title' );
285 $_lesson_thumbnail_id = Input::post( '_lesson_thumbnail_id', 0, Input::TYPE_INT );
286 $lesson_content = Input::post( 'lesson_content', '', Input::TYPE_KSES_POST );
287 $is_html_active = Input::post( 'is_html_active' ) === 'true' ? true : false;
288 $raw_html_content = Input::post( 'tutor_lesson_modal_editor', '', Input::TYPE_KSES_POST );
289 $post_content = $is_html_active ? $raw_html_content : $lesson_content;
290
291 $lesson_data = array(
292 'post_type' => $this->lesson_post_type,
293 'post_title' => $title,
294 'post_name' => sanitize_title( $title ),
295 'post_content' => $post_content,
296 'post_status' => 'publish',
297 'comment_status' => 'open',
298 'post_author' => get_current_user_id(),
299 'post_parent' => $topic_id,
300 );
301
302 if ( 0 === $lesson_id ) {
303 $lesson_data['menu_order'] = tutor_utils()->get_next_course_content_order_id( $topic_id );
304 $lesson_id = wp_insert_post( $lesson_data );
305
306 if ( $lesson_id ) {
307 do_action( 'tutor/lesson/created', $lesson_id );
308 } else {
309 wp_send_json_error( array( 'message' => __( 'Couldn\'t create lesson.', 'tutor' ) ) );
310 }
311 } else {
312 $lesson_data['ID'] = $lesson_id;
313
314 if ( ! tutor_utils()->can_user_manage( 'lesson', $lesson_id ) ) {
315 wp_send_json_error( array( 'message' => tutor_utils()->error_message() ) );
316 }
317
318 do_action( 'tutor/lesson_update/before', $lesson_id );
319 wp_update_post( $lesson_data );
320 if ( $_lesson_thumbnail_id ) {
321 update_post_meta( $lesson_id, '_thumbnail_id', $_lesson_thumbnail_id );
322 } else {
323 delete_post_meta( $lesson_id, '_thumbnail_id' );
324 }
325
326 do_action( 'tutor/lesson_update/after', $lesson_id );
327 }
328
329 ob_start();
330 include tutor()->path . 'views/metabox/course-contents.php';
331 $course_contents = ob_get_clean();
332
333 wp_send_json_success( array( 'course_contents' => $course_contents ) );
334 }
335
336 /**
337 * Delete Lesson from course builder by ID
338 *
339 * @since 1.0.0
340 *
341 * @return void
342 */
343 public function tutor_delete_lesson_by_id() {
344 tutor_utils()->checking_nonce();
345
346 $lesson_id = Input::post( 'lesson_id', 0, Input::TYPE_INT );
347
348 if ( ! tutor_utils()->can_user_manage( 'lesson', $lesson_id ) ) {
349 wp_send_json_error( array( 'message' => __( 'Access Denied', 'tutor' ) ) );
350 }
351
352 wp_delete_post( $lesson_id, true );
353 wp_send_json_success();
354 }
355
356
357 /**
358 * Changed the URI based
359 *
360 * @since 1.0.0
361 *
362 * @param string $uri URI.
363 * @param integer $lesson_id lesson ID.
364 *
365 * @return string
366 */
367 public function change_lesson_permalink( $uri, $lesson_id ) {
368 $post = get_post( $lesson_id );
369
370 if ( $post && $post->post_type === $this->lesson_post_type ) {
371 $uri_base = trailingslashit( site_url() );
372
373 $sample_course = 'sample-course';
374 $is_course = tutor_utils()->get_course_id_by( 'lesson', get_the_ID() );
375 if ( $is_course ) {
376 $course = get_post( $is_course );
377 if ( $course ) {
378 $sample_course = $course->post_name;
379 }
380 }
381
382 $new_course_base = $uri_base . "course/{$sample_course}/lesson/%pagename%/";
383 $uri[0] = $new_course_base;
384 }
385
386 return $uri;
387 }
388
389 /**
390 * Add column to lesson HTML table
391 *
392 * @since 1.0.0
393 *
394 * @param array $columns columns.
395 * @return array
396 */
397 public function add_column( $columns ) {
398 $date_col = $columns['date'];
399 unset( $columns['date'] );
400 $columns['course'] = __( 'Course', 'tutor' );
401 $columns['date'] = $date_col;
402
403 return $columns;
404 }
405
406 /**
407 * Add custom lesson column.
408 *
409 * @since 1.0.0
410 *
411 * @param string $column column name.
412 * @param integer $post_id post ID.
413 *
414 * @return mixed
415 */
416 public function custom_lesson_column( $column, $post_id ) {
417 if ( 'course' === $column ) {
418
419 $course_id = tutor_utils()->get_course_id_by( 'lesson', $post_id );
420 if ( $course_id ) {
421 echo wp_kses(
422 '<a href="' . admin_url( 'post.php?post=' . $course_id . '&action=edit' ) . '">' . get_the_title( $course_id ) . '</a>',
423 array( 'a' => array( 'href' => true ) )
424 );
425 }
426 }
427 }
428
429 /**
430 * Mark lesson completed
431 *
432 * @since 1.0.0
433 *
434 * @return void
435 */
436 public function mark_lesson_complete() {
437 if ( 'tutor_complete_lesson' !== Input::post( 'tutor_action' ) ) {
438 return;
439 }
440 // Checking nonce.
441 tutor_utils()->checking_nonce();
442
443 $user_id = get_current_user_id();
444
445 // TODO: need to show view if not signed_in.
446 if ( ! $user_id ) {
447 die( esc_html__( 'Please Sign-In', 'tutor' ) );
448 }
449
450 $lesson_id = Input::post( 'lesson_id', 0, Input::TYPE_INT );
451
452 if ( ! $lesson_id ) {
453 return;
454 }
455
456 $validated = apply_filters( 'tutor_validate_lesson_complete', true, $user_id, $lesson_id );
457 if ( ! $validated ) {
458 return;
459 }
460
461 do_action( 'tutor_lesson_completed_before', $lesson_id );
462 /**
463 * Marking lesson at user meta, meta format, _tutor_completed_lesson_id_{id} and value = tutor_time();
464 */
465 LessonModel::mark_lesson_complete( $lesson_id );
466
467 do_action( 'tutor_lesson_completed_email_after', $lesson_id, $user_id );
468 do_action( 'tutor_lesson_completed_after', $lesson_id, $user_id );
469 }
470
471 /**
472 * Render the lesson content
473 *
474 * @since 1.0.0
475 *
476 * @return void
477 */
478 public function tutor_render_lesson_content() {
479 tutor_utils()->checking_nonce();
480
481 $lesson_id = Input::post( 'lesson_id', 0, Input::TYPE_INT );
482
483 $ancestors = get_post_ancestors( $lesson_id );
484 $course_id = ! empty( $ancestors ) ? array_pop( $ancestors ) : $lesson_id;
485
486 // Course must be public or current user must be enrolled to access this lesson.
487 if ( get_post_meta( $course_id, '_tutor_is_public_course', true ) !== 'yes' && ! tutor_utils()->is_enrolled( $course_id ) ) {
488
489 $is_admin = tutor_utils()->has_user_role( 'administrator' );
490 $allowed = $is_admin ? true : tutor_utils()->is_instructor_of_this_course( get_current_user_id(), $course_id );
491
492 if ( ! $allowed ) {
493 http_response_code( 400 );
494 exit;
495 }
496 }
497
498 ob_start();
499 global $post;
500
501 $post = get_post( $lesson_id ); //phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
502 setup_postdata( $post );
503 tutor_lesson_content();
504 wp_reset_postdata();
505
506 $html = ob_get_clean();
507
508 wp_send_json_success( array( 'html' => $html ) );
509 }
510
511 /**
512 * Load next course item automatically
513 *
514 * @since 1.4.9
515 *
516 * @return void
517 */
518 public function autoload_next_course_content() {
519 tutor_utils()->checking_nonce();
520
521 $post_id = Input::post( 'post_id', 0, Input::TYPE_INT );
522 $content_id = tutor_utils()->get_post_id( $post_id );
523 $contents = tutor_utils()->get_course_prev_next_contents_by_id( $content_id );
524
525 $autoload_course_content = (bool) get_tutor_option( 'autoload_next_course_content' );
526 $next_url = false;
527 if ( $autoload_course_content ) {
528 $next_url = get_the_permalink( $contents->next_id );
529 }
530 wp_send_json_success( array( 'next_url' => $next_url ) );
531 }
532
533 /**
534 * Load next course item after click complete button
535 *
536 * @since 1.5.3
537 *
538 * @param integer $content_id content ID.
539 * @return void
540 */
541 public function tutor_lesson_completed_after( $content_id ) {
542 $contents = tutor_utils()->get_course_prev_next_contents_by_id( $content_id );
543 $autoload_course_content = (bool) get_tutor_option( 'autoload_next_course_content' );
544 if ( $autoload_course_content ) {
545 wp_safe_redirect( get_the_permalink( $contents->next_id ) );
546 } else {
547 wp_safe_redirect( get_the_permalink( $content_id ) );
548 }
549 die();
550 }
551
552 /**
553 * Replay lesson comment
554 *
555 * @since 1.0.0
556 *
557 * @return void|null
558 */
559 public function reply_lesson_comment() {
560 tutor_utils()->checking_nonce();
561 $comment = Input::post( 'comment', '', Input::TYPE_KSES_POST );
562 if ( 0 === strlen( $comment ) ) {
563 wp_send_json_error();
564 return;
565 }
566
567 $comment_data = array(
568 'comment_content' => $comment,
569 'comment_post_ID' => Input::post( 'comment_post_ID', 0, Input::TYPE_INT ),
570 'comment_parent' => Input::post( 'comment_parent', 0, Input::TYPE_INT ),
571 );
572 $comment_id = self::create_comment( $comment_data );
573 if ( false === $comment_id ) {
574 wp_send_json_error();
575 return;
576 }
577 $reply = get_comment( $comment_id );
578 do_action( 'tutor_reply_lesson_comment_thread', $comment_id, $comment_data );
579
580 ob_start();
581 ?>
582 <div class="tutor-comments-list tutor-child-comment tutor-mt-32" id="lesson-comment-<?php echo esc_attr( $reply->comment_ID ); ?>">
583 <div class="comment-avatar">
584 <img src="<?php echo esc_url( get_avatar_url( $reply->user_id ) ); ?>" alt="">
585 </div>
586 <div class="tutor-single-comment">
587 <div class="tutor-actual-comment tutor-mb-12">
588 <div class="tutor-comment-author">
589 <span class="tutor-fs-6 tutor-fw-bold">
590 <?php echo esc_html( $reply->comment_author ); ?>
591 </span>
592 <span class="tutor-fs-7 tutor-ml-0 tutor-ml-sm-10">
593 <?php echo esc_html( human_time_diff( strtotime( $reply->comment_date ), tutor_time() ) . __( ' ago', 'tutor' ) ); ?>
594 </span>
595 </div>
596 <div class="tutor-comment-text tutor-fs-6 tutor-mt-4">
597 <?php echo esc_html( $reply->comment_content ); ?>
598 </div>
599 </div>
600 </div>
601 </div>
602 <?php
603 $html = ob_get_clean();
604 wp_send_json_success( array( 'html' => $html ) );
605 }
606
607 /**
608 * Get comments
609 *
610 * @since 2.0.6
611 * @see Checkout arguments details: https://developer.wordpress.org/reference/classes/wp_comment_query/__construct/
612 *
613 * @param array $args arguments.
614 * @return mixed based on arguments
615 */
616 public static function get_comments( array $args ) {
617 $comments = get_comments( $args );
618 return $comments;
619 }
620
621 /**
622 * Create comment
623 *
624 * @since 1.0.0
625 *
626 * @param array $request request.
627 * @return mixed comment id on success, false on failure
628 */
629 public static function create_comment( array $request ) {
630 $current_user = wp_get_current_user();
631 $default_data = array(
632 'comment_content' => '',
633 'comment_post_ID' => '',
634 'comment_parent' => '',
635 'user_id' => $current_user->ID,
636 'comment_author' => $current_user->user_login,
637 'comment_author_email' => $current_user->user_email,
638 'comment_author_url' => $current_user->user_url,
639 'comment_agent' => 'Tutor',
640 );
641 $comment_data = wp_parse_args( $request, $default_data );
642 return wp_insert_comment( $comment_data );
643 }
644
645 }
646
647
648