PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 3.7.0
Tutor LMS – eLearning and online course solution v3.7.0
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 11 months ago Admin.php 11 months ago Ajax.php 1 year ago Announcements.php 1 year ago Assets.php 11 months ago Backend_Page_Trait.php 1 year ago BaseController.php 1 year ago Config.php 11 months ago Container.php 11 months ago Course.php 11 months ago Course_Embed.php 3 years ago Course_Filter.php 1 year ago Course_List.php 1 year ago Course_Settings_Tabs.php 1 year ago Course_Widget.php 1 year ago Custom_Validation.php 3 years ago Dashboard.php 1 year ago Earnings.php 1 year ago FormHandler.php 2 years ago Frontend.php 1 year ago Gutenberg.php 1 year ago Icon.php 11 months ago Input.php 1 year ago Instructor.php 1 year ago Instructors_List.php 11 months ago Lesson.php 11 months ago Options_V2.php 11 months ago Permalink.php 2 years ago Post_types.php 1 year ago Private_Course_Access.php 1 year ago Q_And_A.php 11 months ago Question_Answers_List.php 11 months ago Quiz.php 11 months ago QuizBuilder.php 11 months ago Quiz_Attempts_List.php 11 months ago RestAPI.php 2 years ago Reviews.php 11 months ago Rewrite_Rules.php 2 years ago Shortcode.php 1 year ago Singleton.php 1 year ago Student.php 1 year ago Students_List.php 1 year ago Taxonomies.php 1 year ago Template.php 11 months ago Theme_Compatibility.php 3 years ago Tools.php 1 year ago Tools_V2.php 1 year ago Tutor.php 11 months ago TutorEDD.php 1 year ago Tutor_Base.php 2 years ago Tutor_Setup.php 1 year ago Upgrader.php 1 year ago User.php 1 year ago Utils.php 11 months ago Video_Stream.php 3 years ago WhatsNew.php 2 years ago Withdraw.php 1 year ago Withdraw_Requests_List.php 11 months ago WooCommerce.php 1 year ago
Lesson.php
614 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\Helpers\HttpHelper;
18 use Tutor\Helpers\ValidationHelper;
19 use Tutor\Models\LessonModel;
20 use Tutor\Traits\JsonResponse;
21
22 /**
23 * Lesson class
24 *
25 * @since 1.0.0
26 */
27 class Lesson extends Tutor_Base {
28 use JsonResponse;
29
30 /**
31 * Register hooks
32 *
33 * @since 1.0.0
34 * @since 3.7.0 param register hook added.
35 *
36 * @param bool $register_hooks register hooks or not.
37 *
38 * @return void
39 */
40 public function __construct( $register_hooks = true ) {
41 parent::__construct();
42
43 if ( ! $register_hooks ) {
44 return;
45 }
46
47 add_action( 'save_post_' . $this->lesson_post_type, array( $this, 'save_lesson_meta' ) );
48
49 add_action( 'wp_ajax_tutor_lesson_details', array( $this, 'ajax_lesson_details' ) );
50 add_action( 'wp_ajax_tutor_save_lesson', array( $this, 'ajax_save_lesson' ) );
51 add_action( 'wp_ajax_tutor_delete_lesson', array( $this, 'ajax_delete_lesson' ) );
52
53 add_filter( 'get_sample_permalink', array( $this, 'change_lesson_permalink' ), 10, 2 );
54
55 /**
56 * Frontend Action
57 */
58 add_action( 'template_redirect', array( $this, 'mark_lesson_complete' ) );
59
60 add_action( 'wp_ajax_tutor_render_lesson_content', array( $this, 'tutor_render_lesson_content' ) );
61
62 /**
63 * For public course access
64 */
65 add_action( 'wp_ajax_nopriv_tutor_render_lesson_content', array( $this, 'tutor_render_lesson_content' ) );
66
67 /**
68 * Autoplay next video
69 *
70 * @since 1.4.9
71 */
72 add_action( 'wp_ajax_autoload_next_course_content', array( $this, 'autoload_next_course_content' ) );
73
74 /**
75 * Load next course item after click complete button
76 *
77 * @since 1.5.3
78 */
79 add_action( 'tutor_lesson_completed_after', array( $this, 'tutor_lesson_completed_after' ), 999 );
80
81 /**
82 * Lesson comment & reply ajax handler
83 *
84 * @since 2.0.0
85 */
86 add_action( 'wp_ajax_tutor_single_course_lesson_load_more', array( $this, 'tutor_single_course_lesson_load_more' ) );
87 add_action( 'wp_ajax_tutor_create_lesson_comment', array( $this, 'tutor_single_course_lesson_load_more' ) );
88 add_action( 'wp_ajax_tutor_reply_lesson_comment', array( $this, 'reply_lesson_comment' ) );
89 }
90
91 /**
92 * Manage load more & comment create
93 *
94 * @since 2.0.6
95 * @return void send wp json data
96 */
97 public function tutor_single_course_lesson_load_more() {
98 tutor_utils()->checking_nonce();
99 $comment = Input::post( 'comment', '', Input::TYPE_KSES_POST );
100 if ( 'tutor_create_lesson_comment' === Input::post( 'action' ) && strlen( $comment ) > 0 ) {
101 $comment_data = array(
102 'comment_content' => $comment,
103 'comment_post_ID' => Input::post( 'comment_post_ID', 0, Input::TYPE_INT ),
104 'comment_parent' => Input::post( 'comment_parent', 0, Input::TYPE_INT ),
105 );
106 self::create_comment( $comment_data );
107 do_action( 'tutor_new_comment_added', $comment_data );
108 }
109 ob_start();
110 tutor_load_template( 'single.lesson.comment' );
111 $html = ob_get_clean();
112 wp_send_json_success( array( 'html' => $html ) );
113 }
114
115 /**
116 * Saving lesson meta and assets
117 *
118 * @since 1.0.0
119 *
120 * @param integer $post_ID post ID.
121 *
122 * @return void
123 */
124 public function save_lesson_meta( $post_ID ) {
125 $thumbnail_id = Input::post( 'thumbnail_id', 0, Input::TYPE_INT );
126 if ( $thumbnail_id ) {
127 update_post_meta( $post_ID, '_thumbnail_id', $thumbnail_id );
128 } else {
129 delete_post_meta( $post_ID, '_thumbnail_id' );
130 }
131
132 $video_source = sanitize_text_field( tutor_utils()->array_get( 'video.source', $_POST ) ); //phpcs:ignore
133 if ( '-1' === $video_source ) {
134 delete_post_meta( $post_ID, '_video' );
135 } elseif ( $video_source ) {
136
137 // Sanitize data through helper method.
138 $video = Input::sanitize_array(
139 $_POST['video'] ?? array(), //phpcs:ignore
140 array(
141 'source_external_url' => 'esc_url',
142 'source_embedded' => 'wp_kses_post',
143 ),
144 true
145 );
146 update_post_meta( $post_ID, '_video', $video );
147 }
148
149 // Attachments.
150 $attachments = array();
151 // phpcs:disable WordPress.Security.NonceVerification.Missing
152 if ( ! empty( $_POST['tutor_attachments'] ) ) {
153 //phpcs:ignore -- data sanitized through helper method.
154 $attachments = tutor_utils()->sanitize_array( wp_unslash( $_POST['tutor_attachments'] ) );
155 $attachments = array_unique( $attachments );
156 }
157
158 /**
159 * If !empty attachment then update meta else
160 * delete meta key to prevent empty data in db
161 *
162 * @since 1.8.9
163 */
164 if ( ! empty( $attachments ) ) {
165 update_post_meta( $post_ID, '_tutor_attachments', $attachments );
166 } else {
167 delete_post_meta( $post_ID, '_tutor_attachments' );
168 }
169
170 }
171
172 /**
173 * Get lesson details data.
174 *
175 * @since 3.0.0
176 *
177 * @return void
178 */
179 public function ajax_lesson_details() {
180 if ( ! tutor_utils()->is_nonce_verified() ) {
181 $this->json_response( tutor_utils()->error_message( 'nonce' ), null, HttpHelper::STATUS_BAD_REQUEST );
182 }
183
184 $topic_id = Input::post( 'topic_id', 0, Input::TYPE_INT );
185 $lesson_id = Input::post( 'lesson_id', 0, Input::TYPE_INT );
186
187 if ( ! tutor_utils()->can_user_manage( 'topic', $topic_id ) ) {
188 $this->json_response(
189 tutor_utils()->error_message(),
190 null,
191 HttpHelper::STATUS_FORBIDDEN
192 );
193 }
194
195 if ( 0 !== $lesson_id ) {
196 if ( ! tutor_utils()->can_user_manage( 'lesson', $lesson_id ) ) {
197 $this->json_response(
198 tutor_utils()->error_message(),
199 null,
200 HttpHelper::STATUS_FORBIDDEN
201 );
202 }
203 }
204
205 $data = LessonModel::get_lesson_details( $lesson_id );
206
207 $this->json_response(
208 __( 'Lesson data fetched successfully', 'tutor' ),
209 $data
210 );
211 }
212
213 /**
214 * Create or update lesson.
215 *
216 * @since 1.0.0
217 * @since 1.5.1 updated
218 * @since 3.0.0 refactor and response updated.
219 *
220 * @return void
221 */
222 public function ajax_save_lesson() {
223 if ( ! tutor_utils()->is_nonce_verified() ) {
224 $this->json_response( tutor_utils()->error_message( 'nonce' ), null, HttpHelper::STATUS_BAD_REQUEST );
225 }
226
227 /**
228 * Allow iframe inside lesson content to support
229 * embed video & other stuff
230 *
231 * @since 2.1.6
232 */
233 add_filter( 'wp_kses_allowed_html', Input::class . '::allow_iframe', 10, 2 );
234
235 $is_update = false;
236
237 $lesson_id = Input::post( 'lesson_id', 0, Input::TYPE_INT );
238 $topic_id = Input::post( 'topic_id', 0, Input::TYPE_INT );
239 $course_id = tutor_utils()->get_course_id_by( 'topic', $topic_id );
240
241 if ( $lesson_id ) {
242 $is_update = true;
243 }
244
245 if ( ! tutor_utils()->can_user_manage( 'topic', $topic_id ) ) {
246 $this->json_response(
247 tutor_utils()->error_message(),
248 null,
249 HttpHelper::STATUS_FORBIDDEN
250 );
251 }
252
253 $title = Input::post( 'title' );
254 $description = Input::post( 'description', '', Input::TYPE_KSES_POST );
255 $is_html_active = Input::post( 'is_html_active' ) === 'true' ? true : false;
256 $raw_html_content = Input::post( 'tutor_lesson_modal_editor', '', Input::TYPE_KSES_POST );
257 $post_content = $is_html_active ? $raw_html_content : $description;
258
259 $rules = array(
260 'topic_id' => 'required|numeric',
261 'lesson_id' => 'if_input|numeric',
262 );
263
264 //phpcs:ignore WordPress.Security.NonceVerification.Missing
265 $params = Input::sanitize_array( $_POST, array( 'description' => 'wp_kses_post' ) );
266
267 $validation = ValidationHelper::validate( $rules, $params );
268 if ( ! $validation->success ) {
269 $this->json_response(
270 __( 'Invalid inputs', 'tutor' ),
271 $validation->errors,
272 HttpHelper::STATUS_UNPROCESSABLE_ENTITY
273 );
274 }
275
276 $lesson_data = array(
277 'post_type' => $this->lesson_post_type,
278 'post_title' => $title,
279 'post_name' => sanitize_title( $title ),
280 'post_content' => $post_content,
281 'post_status' => 'publish',
282 'comment_status' => 'open',
283 'post_author' => get_current_user_id(),
284 'post_parent' => $topic_id,
285 );
286
287 if ( ! $is_update ) {
288 $lesson_data['menu_order'] = tutor_utils()->get_next_course_content_order_id( $topic_id );
289 $lesson_id = wp_insert_post( $lesson_data );
290
291 if ( $lesson_id ) {
292 do_action( 'tutor/lesson/created', $lesson_id );
293 } else {
294 $this->json_response(
295 tutor_utils()->error_message(),
296 null,
297 HttpHelper::STATUS_INTERNAL_SERVER_ERROR
298 );
299 }
300 } else {
301 $lesson_data['ID'] = $lesson_id;
302
303 if ( ! tutor_utils()->can_user_manage( 'lesson', $lesson_id ) ) {
304 $this->json_response(
305 tutor_utils()->error_message(),
306 null,
307 HttpHelper::STATUS_FORBIDDEN
308 );
309 }
310
311 do_action( 'tutor/lesson_update/before', $lesson_id );
312 wp_update_post( $lesson_data );
313 do_action( 'tutor/lesson_update/after', $lesson_id );
314 }
315
316 if ( $is_update ) {
317 $this->json_response(
318 __( 'Lesson updated successfully', 'tutor' ),
319 $lesson_id
320 );
321 } else {
322 $this->json_response(
323 __( 'Lesson created successfully', 'tutor' ),
324 $lesson_id,
325 HttpHelper::STATUS_CREATED
326 );
327 }
328 }
329
330 /**
331 * Delete Lesson from course builder by ID
332 *
333 * @since 1.0.0
334 * @since 3.0.0 refactor and update response.
335 *
336 * @return void
337 */
338 public function ajax_delete_lesson() {
339 tutor_utils()->check_nonce();
340
341 $lesson_id = Input::post( 'lesson_id', 0, Input::TYPE_INT );
342
343 if ( ! tutor_utils()->can_user_manage( 'lesson', $lesson_id ) ) {
344 $this->json_response(
345 tutor_utils()->error_message(),
346 null,
347 HttpHelper::STATUS_FORBIDDEN
348 );
349 }
350
351 $content = __( 'Lesson', 'tutor' );
352 $post_type = get_post_type( $lesson_id );
353 if ( tutor()->assignment_post_type === $post_type ) {
354 $content = __( 'Assignment', 'tutor' );
355 }
356
357 do_action( 'tutor_before_delete_course_content', 0, $lesson_id );
358
359 wp_delete_post( $lesson_id, true );
360 /* translators: %s refers to the name of the content being deleted */
361 $this->json_response( sprintf( __( '%s deleted successfully', 'tutor' ), $content ) );
362 }
363
364
365 /**
366 * Changed the URI based
367 *
368 * @since 1.0.0
369 *
370 * @param string $uri URI.
371 * @param integer $lesson_id lesson ID.
372 *
373 * @return string
374 */
375 public function change_lesson_permalink( $uri, $lesson_id ) {
376 $post = get_post( $lesson_id );
377
378 if ( $post && $post->post_type === $this->lesson_post_type ) {
379 $uri_base = trailingslashit( site_url() );
380
381 $sample_course = 'sample-course';
382 $is_course = tutor_utils()->get_course_id_by( 'lesson', get_the_ID() );
383 if ( $is_course ) {
384 $course = get_post( $is_course );
385 if ( $course ) {
386 $sample_course = $course->post_name;
387 }
388 }
389
390 $new_course_base = $uri_base . "course/{$sample_course}/lesson/%pagename%/";
391 $uri[0] = $new_course_base;
392 }
393
394 return $uri;
395 }
396
397 /**
398 * Mark lesson completed
399 *
400 * @since 1.0.0
401 *
402 * @return void
403 */
404 public function mark_lesson_complete() {
405 if ( 'tutor_complete_lesson' !== Input::post( 'tutor_action' ) ) {
406 return;
407 }
408 // Checking nonce.
409 tutor_utils()->checking_nonce();
410
411 $user_id = get_current_user_id();
412
413 // TODO: need to show view if not signed_in.
414 if ( ! $user_id ) {
415 die( esc_html__( 'Please Sign-In', 'tutor' ) );
416 }
417
418 $lesson_id = Input::post( 'lesson_id', 0, Input::TYPE_INT );
419
420 if ( ! $lesson_id ) {
421 return;
422 }
423
424 $validated = apply_filters( 'tutor_validate_lesson_complete', true, $user_id, $lesson_id );
425 if ( ! $validated ) {
426 return;
427 }
428
429 do_action( 'tutor_lesson_completed_before', $lesson_id );
430 /**
431 * Marking lesson at user meta, meta format, _tutor_completed_lesson_id_{id} and value = tutor_time();
432 */
433 LessonModel::mark_lesson_complete( $lesson_id );
434
435 do_action( 'tutor_lesson_completed_email_after', $lesson_id, $user_id );
436 do_action( 'tutor_lesson_completed_after', $lesson_id, $user_id );
437 }
438
439 /**
440 * Render the lesson content
441 *
442 * @since 1.0.0
443 *
444 * @return void
445 */
446 public function tutor_render_lesson_content() {
447 tutor_utils()->checking_nonce();
448
449 $lesson_id = Input::post( 'lesson_id', 0, Input::TYPE_INT );
450
451 $ancestors = get_post_ancestors( $lesson_id );
452 $course_id = ! empty( $ancestors ) ? array_pop( $ancestors ) : $lesson_id;
453
454 // Course must be public or current user must be enrolled to access this lesson.
455 if ( get_post_meta( $course_id, '_tutor_is_public_course', true ) !== 'yes' && ! tutor_utils()->is_enrolled( $course_id ) ) {
456
457 $is_admin = tutor_utils()->has_user_role( 'administrator' );
458 $allowed = $is_admin ? true : tutor_utils()->is_instructor_of_this_course( get_current_user_id(), $course_id );
459
460 if ( ! $allowed ) {
461 http_response_code( 400 );
462 exit;
463 }
464 }
465
466 ob_start();
467 global $post;
468
469 $post = get_post( $lesson_id ); //phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
470 setup_postdata( $post );
471 tutor_lesson_content();
472 wp_reset_postdata();
473
474 $html = ob_get_clean();
475
476 wp_send_json_success( array( 'html' => $html ) );
477 }
478
479 /**
480 * Load next course item automatically
481 *
482 * @since 1.4.9
483 *
484 * @return void
485 */
486 public function autoload_next_course_content() {
487 tutor_utils()->checking_nonce();
488
489 $post_id = Input::post( 'post_id', 0, Input::TYPE_INT );
490 $content_id = tutor_utils()->get_post_id( $post_id );
491 $contents = tutor_utils()->get_course_prev_next_contents_by_id( $content_id );
492
493 $autoload_course_content = (bool) get_tutor_option( 'autoload_next_course_content' );
494 $next_url = false;
495 if ( $autoload_course_content ) {
496 $next_url = get_the_permalink( $contents->next_id );
497 }
498 wp_send_json_success( array( 'next_url' => $next_url ) );
499 }
500
501 /**
502 * Load next course item after click complete button
503 *
504 * @since 1.5.3
505 *
506 * @param integer $content_id content ID.
507 * @return void
508 */
509 public function tutor_lesson_completed_after( $content_id ) {
510 $contents = tutor_utils()->get_course_prev_next_contents_by_id( $content_id );
511 $autoload_course_content = (bool) get_tutor_option( 'autoload_next_course_content' );
512 if ( $autoload_course_content ) {
513 wp_safe_redirect( get_the_permalink( $contents->next_id ) );
514 } else {
515 wp_safe_redirect( get_the_permalink( $content_id ) );
516 }
517 die();
518 }
519
520 /**
521 * Replay lesson comment
522 *
523 * @since 1.0.0
524 *
525 * @return void|null
526 */
527 public function reply_lesson_comment() {
528 tutor_utils()->checking_nonce();
529 $comment = Input::post( 'comment', '', Input::TYPE_KSES_POST );
530 if ( 0 === strlen( $comment ) ) {
531 wp_send_json_error();
532 return;
533 }
534
535 $comment_data = array(
536 'comment_content' => $comment,
537 'comment_post_ID' => Input::post( 'comment_post_ID', 0, Input::TYPE_INT ),
538 'comment_parent' => Input::post( 'comment_parent', 0, Input::TYPE_INT ),
539 );
540 $comment_id = self::create_comment( $comment_data );
541 if ( false === $comment_id ) {
542 wp_send_json_error();
543 return;
544 }
545 $reply = get_comment( $comment_id );
546 do_action( 'tutor_reply_lesson_comment_thread', $comment_id, $comment_data );
547
548 ob_start();
549 ?>
550 <div class="tutor-comments-list tutor-child-comment tutor-mt-32" id="lesson-comment-<?php echo esc_attr( $reply->comment_ID ); ?>">
551 <div class="comment-avatar">
552 <img src="<?php echo esc_url( get_avatar_url( $reply->user_id ) ); ?>" alt="">
553 </div>
554 <div class="tutor-single-comment">
555 <div class="tutor-actual-comment tutor-mb-12">
556 <div class="tutor-comment-author">
557 <span class="tutor-fs-6 tutor-fw-bold">
558 <?php echo esc_html( $reply->comment_author ); ?>
559 </span>
560 <span class="tutor-fs-7 tutor-ml-0 tutor-ml-sm-10">
561 <?php echo esc_html( human_time_diff( strtotime( $reply->comment_date ), tutor_time() ) . __( ' ago', 'tutor' ) ); ?>
562 </span>
563 </div>
564 <div class="tutor-comment-text tutor-fs-6 tutor-mt-4">
565 <?php echo esc_html( $reply->comment_content ); ?>
566 </div>
567 </div>
568 </div>
569 </div>
570 <?php
571 $html = ob_get_clean();
572 wp_send_json_success( array( 'html' => $html ) );
573 }
574
575 /**
576 * Get comments
577 *
578 * @since 2.0.6
579 * @see Checkout arguments details: https://developer.wordpress.org/reference/classes/wp_comment_query/__construct/
580 *
581 * @param array $args arguments.
582 * @return mixed based on arguments
583 */
584 public static function get_comments( array $args ) {
585 $comments = get_comments( $args );
586 return $comments;
587 }
588
589 /**
590 * Create comment
591 *
592 * @since 1.0.0
593 *
594 * @param array $request request.
595 * @return mixed comment id on success, false on failure
596 */
597 public static function create_comment( array $request ) {
598 $current_user = wp_get_current_user();
599 $default_data = array(
600 'comment_content' => '',
601 'comment_post_ID' => '',
602 'comment_parent' => '',
603 'user_id' => $current_user->ID,
604 'comment_author' => $current_user->user_login,
605 'comment_author_email' => $current_user->user_email,
606 'comment_author_url' => $current_user->user_url,
607 'comment_agent' => 'Tutor',
608 );
609 $comment_data = wp_parse_args( $request, $default_data );
610 return wp_insert_comment( $comment_data );
611 }
612
613 }
614