PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 3.7.2
Tutor LMS – eLearning and online course solution v3.7.2
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 10 months ago Course_Embed.php 3 years ago Course_Filter.php 1 year ago Course_List.php 10 months 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 10 months ago Input.php 1 year ago Instructor.php 1 year ago Instructors_List.php 11 months ago Lesson.php 10 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 10 months ago Question_Answers_List.php 11 months ago Quiz.php 10 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 10 months ago TutorEDD.php 1 year ago Tutor_Base.php 2 years ago Tutor_Setup.php 1 year ago Upgrader.php 10 months ago User.php 1 year ago Utils.php 10 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 11 months ago
Lesson.php
613 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
240 if ( $lesson_id ) {
241 $is_update = true;
242 }
243
244 if ( ! tutor_utils()->can_user_manage( 'topic', $topic_id ) ) {
245 $this->json_response(
246 tutor_utils()->error_message(),
247 null,
248 HttpHelper::STATUS_FORBIDDEN
249 );
250 }
251
252 $title = Input::post( 'title' );
253 $description = Input::post( 'description', '', Input::TYPE_KSES_POST );
254 $is_html_active = Input::post( 'is_html_active' ) === 'true' ? true : false;
255 $raw_html_content = Input::post( 'tutor_lesson_modal_editor', '', Input::TYPE_KSES_POST );
256 $post_content = $is_html_active ? $raw_html_content : $description;
257
258 $rules = array(
259 'topic_id' => 'required|numeric',
260 'lesson_id' => 'if_input|numeric',
261 );
262
263 //phpcs:ignore WordPress.Security.NonceVerification.Missing
264 $params = Input::sanitize_array( $_POST, array( 'description' => 'wp_kses_post' ) );
265
266 $validation = ValidationHelper::validate( $rules, $params );
267 if ( ! $validation->success ) {
268 $this->json_response(
269 __( 'Invalid inputs', 'tutor' ),
270 $validation->errors,
271 HttpHelper::STATUS_UNPROCESSABLE_ENTITY
272 );
273 }
274
275 $lesson_data = array(
276 'post_type' => $this->lesson_post_type,
277 'post_title' => wp_slash( $title ), // Note: Added wp_slash to support latex syntaxes.
278 'post_name' => sanitize_title( $title ),
279 'post_content' => wp_slash( $post_content ),
280 'post_status' => 'publish',
281 'comment_status' => 'open',
282 'post_author' => get_current_user_id(),
283 'post_parent' => $topic_id,
284 );
285
286 if ( ! $is_update ) {
287 $lesson_data['menu_order'] = tutor_utils()->get_next_course_content_order_id( $topic_id );
288 $lesson_id = wp_insert_post( $lesson_data );
289
290 if ( $lesson_id ) {
291 do_action( 'tutor/lesson/created', $lesson_id );
292 } else {
293 $this->json_response(
294 tutor_utils()->error_message(),
295 null,
296 HttpHelper::STATUS_INTERNAL_SERVER_ERROR
297 );
298 }
299 } else {
300 $lesson_data['ID'] = $lesson_id;
301
302 if ( ! tutor_utils()->can_user_manage( 'lesson', $lesson_id ) ) {
303 $this->json_response(
304 tutor_utils()->error_message(),
305 null,
306 HttpHelper::STATUS_FORBIDDEN
307 );
308 }
309
310 do_action( 'tutor/lesson_update/before', $lesson_id );
311 wp_update_post( $lesson_data );
312 do_action( 'tutor/lesson_update/after', $lesson_id );
313 }
314
315 if ( $is_update ) {
316 $this->json_response(
317 __( 'Lesson updated successfully', 'tutor' ),
318 $lesson_id
319 );
320 } else {
321 $this->json_response(
322 __( 'Lesson created successfully', 'tutor' ),
323 $lesson_id,
324 HttpHelper::STATUS_CREATED
325 );
326 }
327 }
328
329 /**
330 * Delete Lesson from course builder by ID
331 *
332 * @since 1.0.0
333 * @since 3.0.0 refactor and update response.
334 *
335 * @return void
336 */
337 public function ajax_delete_lesson() {
338 tutor_utils()->check_nonce();
339
340 $lesson_id = Input::post( 'lesson_id', 0, Input::TYPE_INT );
341
342 if ( ! tutor_utils()->can_user_manage( 'lesson', $lesson_id ) ) {
343 $this->json_response(
344 tutor_utils()->error_message(),
345 null,
346 HttpHelper::STATUS_FORBIDDEN
347 );
348 }
349
350 $content = __( 'Lesson', 'tutor' );
351 $post_type = get_post_type( $lesson_id );
352 if ( tutor()->assignment_post_type === $post_type ) {
353 $content = __( 'Assignment', 'tutor' );
354 }
355
356 do_action( 'tutor_before_delete_course_content', 0, $lesson_id );
357
358 wp_delete_post( $lesson_id, true );
359 /* translators: %s refers to the name of the content being deleted */
360 $this->json_response( sprintf( __( '%s deleted successfully', 'tutor' ), $content ) );
361 }
362
363
364 /**
365 * Changed the URI based
366 *
367 * @since 1.0.0
368 *
369 * @param string $uri URI.
370 * @param integer $lesson_id lesson ID.
371 *
372 * @return string
373 */
374 public function change_lesson_permalink( $uri, $lesson_id ) {
375 $post = get_post( $lesson_id );
376
377 if ( $post && $post->post_type === $this->lesson_post_type ) {
378 $uri_base = trailingslashit( site_url() );
379
380 $sample_course = 'sample-course';
381 $is_course = tutor_utils()->get_course_id_by( 'lesson', get_the_ID() );
382 if ( $is_course ) {
383 $course = get_post( $is_course );
384 if ( $course ) {
385 $sample_course = $course->post_name;
386 }
387 }
388
389 $new_course_base = $uri_base . "course/{$sample_course}/lesson/%pagename%/";
390 $uri[0] = $new_course_base;
391 }
392
393 return $uri;
394 }
395
396 /**
397 * Mark lesson completed
398 *
399 * @since 1.0.0
400 *
401 * @return void
402 */
403 public function mark_lesson_complete() {
404 if ( 'tutor_complete_lesson' !== Input::post( 'tutor_action' ) ) {
405 return;
406 }
407 // Checking nonce.
408 tutor_utils()->checking_nonce();
409
410 $user_id = get_current_user_id();
411
412 // TODO: need to show view if not signed_in.
413 if ( ! $user_id ) {
414 die( esc_html__( 'Please Sign-In', 'tutor' ) );
415 }
416
417 $lesson_id = Input::post( 'lesson_id', 0, Input::TYPE_INT );
418
419 if ( ! $lesson_id ) {
420 return;
421 }
422
423 $validated = apply_filters( 'tutor_validate_lesson_complete', true, $user_id, $lesson_id );
424 if ( ! $validated ) {
425 return;
426 }
427
428 do_action( 'tutor_lesson_completed_before', $lesson_id );
429 /**
430 * Marking lesson at user meta, meta format, _tutor_completed_lesson_id_{id} and value = tutor_time();
431 */
432 LessonModel::mark_lesson_complete( $lesson_id );
433
434 do_action( 'tutor_lesson_completed_email_after', $lesson_id, $user_id );
435 do_action( 'tutor_lesson_completed_after', $lesson_id, $user_id );
436 }
437
438 /**
439 * Render the lesson content
440 *
441 * @since 1.0.0
442 *
443 * @return void
444 */
445 public function tutor_render_lesson_content() {
446 tutor_utils()->checking_nonce();
447
448 $lesson_id = Input::post( 'lesson_id', 0, Input::TYPE_INT );
449
450 $ancestors = get_post_ancestors( $lesson_id );
451 $course_id = ! empty( $ancestors ) ? array_pop( $ancestors ) : $lesson_id;
452
453 // Course must be public or current user must be enrolled to access this lesson.
454 if ( get_post_meta( $course_id, '_tutor_is_public_course', true ) !== 'yes' && ! tutor_utils()->is_enrolled( $course_id ) ) {
455
456 $is_admin = tutor_utils()->has_user_role( 'administrator' );
457 $allowed = $is_admin ? true : tutor_utils()->is_instructor_of_this_course( get_current_user_id(), $course_id );
458
459 if ( ! $allowed ) {
460 http_response_code( 400 );
461 exit;
462 }
463 }
464
465 ob_start();
466 global $post;
467
468 $post = get_post( $lesson_id ); //phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
469 setup_postdata( $post );
470 tutor_lesson_content();
471 wp_reset_postdata();
472
473 $html = ob_get_clean();
474
475 wp_send_json_success( array( 'html' => $html ) );
476 }
477
478 /**
479 * Load next course item automatically
480 *
481 * @since 1.4.9
482 *
483 * @return void
484 */
485 public function autoload_next_course_content() {
486 tutor_utils()->checking_nonce();
487
488 $post_id = Input::post( 'post_id', 0, Input::TYPE_INT );
489 $content_id = tutor_utils()->get_post_id( $post_id );
490 $contents = tutor_utils()->get_course_prev_next_contents_by_id( $content_id );
491
492 $autoload_course_content = (bool) get_tutor_option( 'autoload_next_course_content' );
493 $next_url = false;
494 if ( $autoload_course_content ) {
495 $next_url = get_the_permalink( $contents->next_id );
496 }
497 wp_send_json_success( array( 'next_url' => $next_url ) );
498 }
499
500 /**
501 * Load next course item after click complete button
502 *
503 * @since 1.5.3
504 *
505 * @param integer $content_id content ID.
506 * @return void
507 */
508 public function tutor_lesson_completed_after( $content_id ) {
509 $contents = tutor_utils()->get_course_prev_next_contents_by_id( $content_id );
510 $autoload_course_content = (bool) get_tutor_option( 'autoload_next_course_content' );
511 if ( $autoload_course_content ) {
512 wp_safe_redirect( get_the_permalink( $contents->next_id ) );
513 } else {
514 wp_safe_redirect( get_the_permalink( $content_id ) );
515 }
516 die();
517 }
518
519 /**
520 * Replay lesson comment
521 *
522 * @since 1.0.0
523 *
524 * @return void|null
525 */
526 public function reply_lesson_comment() {
527 tutor_utils()->checking_nonce();
528 $comment = Input::post( 'comment', '', Input::TYPE_KSES_POST );
529 if ( 0 === strlen( $comment ) ) {
530 wp_send_json_error();
531 return;
532 }
533
534 $comment_data = array(
535 'comment_content' => $comment,
536 'comment_post_ID' => Input::post( 'comment_post_ID', 0, Input::TYPE_INT ),
537 'comment_parent' => Input::post( 'comment_parent', 0, Input::TYPE_INT ),
538 );
539 $comment_id = self::create_comment( $comment_data );
540 if ( false === $comment_id ) {
541 wp_send_json_error();
542 return;
543 }
544 $reply = get_comment( $comment_id );
545 do_action( 'tutor_reply_lesson_comment_thread', $comment_id, $comment_data );
546
547 ob_start();
548 ?>
549 <div class="tutor-comments-list tutor-child-comment tutor-mt-32" id="lesson-comment-<?php echo esc_attr( $reply->comment_ID ); ?>">
550 <div class="comment-avatar">
551 <img src="<?php echo esc_url( get_avatar_url( $reply->user_id ) ); ?>" alt="">
552 </div>
553 <div class="tutor-single-comment">
554 <div class="tutor-actual-comment tutor-mb-12">
555 <div class="tutor-comment-author">
556 <span class="tutor-fs-6 tutor-fw-bold">
557 <?php echo esc_html( $reply->comment_author ); ?>
558 </span>
559 <span class="tutor-fs-7 tutor-ml-0 tutor-ml-sm-10">
560 <?php echo esc_html( human_time_diff( strtotime( $reply->comment_date ), tutor_time() ) . __( ' ago', 'tutor' ) ); ?>
561 </span>
562 </div>
563 <div class="tutor-comment-text tutor-fs-6 tutor-mt-4">
564 <?php echo esc_html( $reply->comment_content ); ?>
565 </div>
566 </div>
567 </div>
568 </div>
569 <?php
570 $html = ob_get_clean();
571 wp_send_json_success( array( 'html' => $html ) );
572 }
573
574 /**
575 * Get comments
576 *
577 * @since 2.0.6
578 * @see Checkout arguments details: https://developer.wordpress.org/reference/classes/wp_comment_query/__construct/
579 *
580 * @param array $args arguments.
581 * @return mixed based on arguments
582 */
583 public static function get_comments( array $args ) {
584 $comments = get_comments( $args );
585 return $comments;
586 }
587
588 /**
589 * Create comment
590 *
591 * @since 1.0.0
592 *
593 * @param array $request request.
594 * @return mixed comment id on success, false on failure
595 */
596 public static function create_comment( array $request ) {
597 $current_user = wp_get_current_user();
598 $default_data = array(
599 'comment_content' => '',
600 'comment_post_ID' => '',
601 'comment_parent' => '',
602 'user_id' => $current_user->ID,
603 'comment_author' => $current_user->user_login,
604 'comment_author_email' => $current_user->user_email,
605 'comment_author_url' => $current_user->user_url,
606 'comment_agent' => 'Tutor',
607 );
608 $comment_data = wp_parse_args( $request, $default_data );
609 return wp_insert_comment( $comment_data );
610 }
611
612 }
613