PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 2.1.0
Tutor LMS – eLearning and online course solution v2.1.0
3.9.15 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 / Ajax.php
tutor / classes Last commit date
Addons.php 3 years ago Admin.php 3 years ago Ajax.php 3 years ago Announcements.php 3 years ago Assets.php 3 years ago Backend_Page_Trait.php 3 years ago Course.php 3 years ago Course_Embed.php 3 years ago Course_Filter.php 3 years ago Course_List.php 3 years ago Course_Settings_Tabs.php 3 years ago Course_Widget.php 4 years ago Custom_Validation.php 4 years ago Dashboard.php 3 years ago FormHandler.php 4 years ago Frontend.php 3 years ago Gutenberg.php 3 years ago Input.php 3 years ago Instructor.php 4 years ago Instructors_List.php 3 years ago Lesson.php 3 years ago Options_V2.php 3 years ago Post_types.php 3 years ago Private_Course_Access.php 4 years ago Q_and_A.php 3 years ago Question_Answers_List.php 4 years ago Quiz.php 3 years ago Quiz_Attempts_List.php 3 years ago RestAPI.php 4 years ago Reviews.php 3 years ago Rewrite_Rules.php 4 years ago Shortcode.php 4 years ago Student.php 4 years ago Students_List.php 4 years ago Taxonomies.php 4 years ago Template.php 3 years ago Theme_Compatibility.php 5 years ago Tools.php 3 years ago Tools_V2.php 4 years ago Tutor.php 3 years ago TutorEDD.php 4 years ago Tutor_Base.php 5 years ago Tutor_List_Table.php 3 years ago Tutor_Setup.php 3 years ago Upgrader.php 4 years ago User.php 4 years ago Utils.php 3 years ago Video_Stream.php 4 years ago Withdraw.php 3 years ago Withdraw_Requests_List.php 3 years ago WooCommerce.php 3 years ago
Ajax.php
587 lines
1 <?php
2 namespace TUTOR;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 use Tutor\Models\LessonModel;
9 /**
10 * Class Ajax
11 * @since 1.0.0
12 */
13 class Ajax {
14 public function __construct() {
15
16 add_action( 'wp_ajax_sync_video_playback', array( $this, 'sync_video_playback' ) );
17 add_action( 'wp_ajax_nopriv_sync_video_playback', array( $this, 'sync_video_playback_noprev' ) );
18 add_action( 'wp_ajax_tutor_place_rating', array( $this, 'tutor_place_rating' ) );
19 add_action( 'wp_ajax_delete_tutor_review', array( $this, 'delete_tutor_review' ) );
20
21 add_action( 'wp_ajax_tutor_course_add_to_wishlist', array( $this, 'tutor_course_add_to_wishlist' ) );
22 add_action( 'wp_ajax_nopriv_tutor_course_add_to_wishlist', array( $this, 'tutor_course_add_to_wishlist' ) );
23
24 /**
25 * Get all addons
26 */
27 add_action( 'wp_ajax_tutor_get_all_addons', array( $this, 'tutor_get_all_addons' ) );
28
29 /**
30 * Addon Enable Disable Control
31 */
32 add_action( 'wp_ajax_addon_enable_disable', array( $this, 'addon_enable_disable' ) );
33
34 /**
35 * Ajax login
36 *
37 * @since v.1.6.3
38 */
39 add_action( 'wp_ajax_nopriv_tutor_user_login', array( $this, 'process_ajax_login' ) );
40
41 /**
42 * Announcement
43 *
44 * @since v.1.7.9
45 */
46 add_action( 'wp_ajax_tutor_announcement_create', array( $this, 'create_or_update_annoucement' ) );
47 add_action( 'wp_ajax_tutor_announcement_delete', array( $this, 'delete_annoucement' ) );
48 }
49
50
51
52 /**
53 * Update video information and data when necessary
54 *
55 * @since v.1.0.0
56 */
57 public function sync_video_playback() {
58 tutor_utils()->checking_nonce();
59
60 $user_id = get_current_user_id();
61 $post_id = isset( $_POST['post_id'] ) ? sanitize_text_field( $_POST['post_id'] ) : 0;
62 $duration = sanitize_text_field( $_POST['duration'] );
63 $currentTime = sanitize_text_field( $_POST['currentTime'] );
64
65 if ( ! tutor_utils()->has_enrolled_content_access( 'lesson', $post_id ) ) {
66 wp_send_json_error( array( 'message' => __( 'Access Denied', 'tutor' ) ) );
67 exit;
68 }
69
70 /**
71 * Update posts attached video
72 */
73 $video = tutor_utils()->get_video( $post_id );
74
75 if ( $duration ) {
76 $video['duration_sec'] = $duration; // secs
77 $video['playtime'] = tutor_utils()->playtime_string( $duration );
78 $video['runtime'] = tutor_utils()->playtime_array( $duration );
79 }
80 tutor_utils()->update_video( $post_id, $video );
81
82 /**
83 * Sync Lesson Reading Info by Users
84 */
85
86 $best_watch_time = tutor_utils()->get_lesson_reading_info( $post_id, $user_id, 'video_best_watched_time' );
87 if ( $best_watch_time < $currentTime ) {
88 LessonModel::update_lesson_reading_info( $post_id, $user_id, 'video_best_watched_time', $currentTime );
89 }
90
91 if ( tutor_utils()->avalue_dot( 'is_ended', $_POST ) ) {
92 LessonModel::mark_lesson_complete( $post_id );
93 }
94 exit();
95 }
96
97 public function sync_video_playback_noprev() {
98
99 }
100
101
102 public function tutor_place_rating() {
103 global $wpdb;
104
105 tutor_utils()->checking_nonce();
106
107 $moderation= tutor_utils()->get_option('enable_course_review_moderation', false, true, true);
108 $rating = sanitize_text_field( tutor_utils()->avalue_dot( 'tutor_rating_gen_input', $_POST ) );
109 $course_id = sanitize_text_field( tutor_utils()->avalue_dot( 'course_id', $_POST ) );
110 $review = sanitize_textarea_field( tutor_utils()->avalue_dot( 'review', $_POST ) );
111
112 ! $rating ? $rating = 0 : 0;
113 $rating > 5 ? $rating = 5 : 0;
114
115 $user_id = get_current_user_id();
116 $user = get_userdata( $user_id );
117 $date = date( 'Y-m-d H:i:s', tutor_time() );
118
119 if ( ! tutor_utils()->has_enrolled_content_access( 'course', $course_id ) ) {
120 wp_send_json_error( array( 'message' => __( 'Access Denied', 'tutor' ) ) );
121 exit;
122 }
123
124 do_action( 'tutor_before_rating_placed' );
125
126 $previous_rating_id = $wpdb->get_var(
127 $wpdb->prepare(
128 "SELECT comment_ID
129 from {$wpdb->comments}
130 WHERE comment_post_ID = %d AND
131 user_id = %d AND
132 comment_type = 'tutor_course_rating'
133 LIMIT 1;",
134 $course_id,
135 $user_id
136 )
137 );
138
139 $review_ID = $previous_rating_id;
140 if ( $previous_rating_id ) {
141 $wpdb->update(
142 $wpdb->comments,
143 array(
144 'comment_content' => $review,
145 'comment_approved' => $moderation ? 'hold' : 'approved',
146 'comment_date' => $date,
147 'comment_date_gmt' => get_gmt_from_date( $date ),
148 ),
149 array( 'comment_ID' => $previous_rating_id )
150 );
151
152 $rating_info = $wpdb->get_row( $wpdb->prepare(
153 "SELECT * FROM {$wpdb->commentmeta}
154 WHERE comment_id = %d
155 AND meta_key = 'tutor_rating'; ",
156 $previous_rating_id
157 ) );
158
159 if ( $rating_info ) {
160 $wpdb->update(
161 $wpdb->commentmeta,
162 array( 'meta_value' => $rating ),
163 array(
164 'comment_id' => $previous_rating_id,
165 'meta_key' => 'tutor_rating',
166 )
167 );
168 } else {
169 $wpdb->insert(
170 $wpdb->commentmeta,
171 array(
172 'comment_id' => $previous_rating_id,
173 'meta_key' => 'tutor_rating',
174 'meta_value' => $rating,
175 )
176 );
177 }
178 } else {
179 $data = array(
180 'comment_post_ID' => esc_sql( $course_id ),
181 'comment_approved' => $moderation ? 'hold' : 'approved',
182 'comment_type' => 'tutor_course_rating',
183 'comment_date' => $date,
184 'comment_date_gmt' => get_gmt_from_date( $date ),
185 'user_id' => $user_id,
186 'comment_author' => $user->user_login,
187 'comment_agent' => 'TutorLMSPlugin',
188 );
189 if ( $review ) {
190 $data['comment_content'] = $review;
191 }
192
193 $wpdb->insert( $wpdb->comments, $data );
194 $comment_id = (int) $wpdb->insert_id;
195 $review_ID = $comment_id;
196
197 if ( $comment_id ) {
198 $result = $wpdb->insert(
199 $wpdb->commentmeta,
200 array(
201 'comment_id' => $comment_id,
202 'meta_key' => 'tutor_rating',
203 'meta_value' => $rating,
204 )
205 );
206
207 do_action( 'tutor_after_rating_placed', $comment_id );
208 }
209 }
210
211 wp_send_json_success(
212 array(
213 'message' => __( 'Rating placed successsully!', 'tutor' ),
214 'review_id' => $review_ID,
215 )
216 );
217 }
218
219 public function delete_tutor_review() {
220 tutor_utils()->checking_nonce();
221
222 $review_id = sanitize_text_field( tutor_utils()->array_get( 'review_id', $_POST ) );
223
224 if ( ! tutor_utils()->can_user_manage( 'review', $review_id, get_current_user_id() ) ) {
225 wp_send_json_error( array( 'message' => __( 'Permissioned Denied!', 'tutor' ) ) );
226 exit;
227 }
228
229 global $wpdb;
230 $wpdb->delete( $wpdb->commentmeta, array( 'comment_id' => $review_id ) );
231 $wpdb->delete( $wpdb->comments, array( 'comment_ID' => $review_id ) );
232
233 wp_send_json_success();
234 }
235
236 public function tutor_course_add_to_wishlist() {
237 tutor_utils()->checking_nonce();
238
239 // Redirect login since only logged in user can add courses to wishlist
240 if ( ! is_user_logged_in() ) {
241 wp_send_json_error(
242 array(
243 'redirect_to' => wp_login_url( wp_get_referer() ),
244 )
245 );
246 }
247
248 global $wpdb;
249 $user_id = get_current_user_id();
250 $course_id = (int) sanitize_text_field( $_POST['course_id'] );
251
252 $if_added_to_list = $wpdb->get_row(
253 $wpdb->prepare(
254 "SELECT * from {$wpdb->usermeta}
255 WHERE user_id = %d
256 AND meta_key = '_tutor_course_wishlist'
257 AND meta_value = %d;",
258 $user_id,
259 $course_id
260 )
261 );
262
263 if ( $if_added_to_list ) {
264 $wpdb->delete(
265 $wpdb->usermeta,
266 array(
267 'user_id' => $user_id,
268 'meta_key' => '_tutor_course_wishlist',
269 'meta_value' => $course_id,
270 )
271 );
272 wp_send_json_success(
273 array(
274 'status' => 'removed',
275 'message' => __( 'Course removed from wish list', 'tutor' ),
276 )
277 );
278 } else {
279 add_user_meta( $user_id, '_tutor_course_wishlist', $course_id );
280 wp_send_json_success(
281 array(
282 'status' => 'added',
283 'message' => __( 'Course added to wish list', 'tutor' ),
284 )
285 );
286 }
287 }
288
289 /**
290 * Prepare addons data
291 */
292 public function prepare_addons_data() {
293 $addons = apply_filters( 'tutor_addons_lists_config', array() );
294 $plugins_data = $addons;
295
296 if ( is_array( $addons ) && count( $addons ) ) {
297 foreach ( $addons as $base_name => $addon ) {
298 $addon_config = tutor_utils()->get_addon_config( $base_name );
299 $is_enabled = (bool) tutor_utils()->avalue_dot( 'is_enable', $addon_config );
300
301 $plugins_data[ $base_name ]['is_enabled'] = $is_enabled;
302
303 $thumbnail_url = tutor()->url . 'assets/images/tutor-plugin.png';
304 if ( file_exists( $addon['path'] . 'assets/images/thumbnail.png' ) ) {
305 $thumbnail_url = $addon['url'] . 'assets/images/thumbnail.png';
306 } elseif ( file_exists( $addon['path'] . 'assets/images/thumbnail.jpg' ) ) {
307 $thumbnail_url = $addon['url'] . 'assets/images/thumbnail.jpg';
308 } elseif ( file_exists( $addon['path'] . 'assets/images/thumbnail.svg' ) ) {
309 $thumbnail_url = $addon['url'] . 'assets/images/thumbnail.svg';
310 }
311
312 $plugins_data[ $base_name ]['thumb_url'] = $thumbnail_url;
313
314 /**
315 * Checking if there any dependant plugin exists
316 */
317 $depends = tutor_utils()->array_get( 'depend_plugins', $addon );
318 $plugins_required = array();
319 if ( tutor_utils()->count( $depends ) ) {
320 foreach ( $depends as $plugin_base => $plugin_name ) {
321 if ( ! is_plugin_active( $plugin_base ) ) {
322 $plugins_required[ $plugin_base ] = $plugin_name;
323 }
324 }
325 }
326
327 $depended_plugins = array();
328 foreach ( $plugins_required as $required_plugin ) {
329 array_push( $depended_plugins, $required_plugin );
330 }
331
332 $plugins_data[ $base_name ]['plugins_required'] = $depended_plugins;
333
334 // Check if it's notifications.
335 if ( function_exists( 'tutor_notifications' ) && $base_name == tutor_notifications()->basename ) {
336
337 $required = array();
338 version_compare( PHP_VERSION, '7.2.5', '>=' ) ? 0 : $required[] = __( 'PHP 7.2.5 or greater is required', 'tutor' );
339 ! is_ssl() ? $required[] = __( 'SSL certificate', 'tutor' ) : 0;
340
341 foreach ( array( 'curl', 'gmp', 'mbstring', 'openssl' ) as $ext ) {
342 ! extension_loaded( $ext ) ? $required[] = 'PHP extension <strong>' . $ext . '</strong>' : 0;
343 }
344
345 $plugins_data[ $base_name ]['ext_required'] = $required;
346 }
347 }
348 }
349
350 $prepared_addons = array();
351 foreach ( $plugins_data as $tutor_addon ) {
352 array_push( $prepared_addons, $tutor_addon );
353 }
354
355 return $prepared_addons;
356 }
357
358 /**
359 * Get all notifications
360 */
361 public function tutor_get_all_addons() {
362
363 // Check and verify the request.
364 tutor_utils()->checking_nonce();
365
366 // All good, let's proceed.
367 $all_addons = $this->prepare_addons_data();
368
369 wp_send_json_success(
370 array(
371 'addons' => $all_addons,
372 )
373 );
374 }
375
376 /**
377 * Method for enable / disable addons
378 */
379 public function addon_enable_disable() {
380
381 if ( ! current_user_can( 'manage_options' ) ) {
382 wp_send_json_error( array( 'message' => __( 'Access Denied', 'tutor' ) ) );
383 }
384
385 $addonsConfig = maybe_unserialize( get_option( 'tutor_addons_config' ) );
386
387 // $isEnable = (bool) sanitize_text_field( tutor_utils()->avalue_dot( 'isEnable', $_POST ) );
388 // $addonFieldName = sanitize_text_field( tutor_utils()->avalue_dot( 'addonFieldName', $_POST ) );
389 $addonFieldNames = json_decode( stripslashes( ( tutor_utils()->avalue_dot( 'addonFieldNames', $_POST ) ) ), true );
390
391 foreach ( $addonFieldNames as $addonFieldName => $isEnable ) {
392 do_action( 'tutor_addon_before_enable_disable' );
393 if ( $isEnable ) {
394 do_action( "tutor_addon_before_enable_{$addonFieldName}" );
395 do_action( 'tutor_addon_before_enable', $addonFieldName );
396 $addonsConfig[ $addonFieldName ]['is_enable'] = 1;
397 update_option( 'tutor_addons_config', $addonsConfig );
398
399 do_action( 'tutor_addon_after_enable', $addonFieldName );
400 do_action( "tutor_addon_after_enable_{$addonFieldName}" );
401 } else {
402 do_action( "tutor_addon_before_disable_{$addonFieldName}" );
403 do_action( 'tutor_addon_before_disable', $addonFieldName );
404 $addonsConfig[ $addonFieldName ]['is_enable'] = 0;
405 update_option( 'tutor_addons_config', $addonsConfig );
406
407 do_action( 'tutor_addon_after_disable', $addonFieldName );
408 do_action( "tutor_addon_after_disable_{$addonFieldName}" );
409 }
410 do_action( 'tutor_addon_after_enable_disable' );
411 }
412
413 wp_send_json_success();
414 }
415
416 /**
417 * Process ajax login
418 *
419 * @since v.1.6.3
420 */
421 public function process_ajax_login() {
422 tutor_utils()->checking_nonce();
423
424 $username = tutor_utils()->array_get( 'log', $_POST );
425 $password = tutor_utils()->array_get( 'pwd', $_POST );
426 $redirect_to = tutor_utils()->array_get( 'redirect_to', $_POST );
427
428 try {
429 $creds = array(
430 'user_login' => trim( wp_unslash( $username ) ),
431 'user_password' => $password,
432 'remember' => isset( $_POST['rememberme'] ),
433 );
434
435 $validation_error = new \WP_Error();
436 $validation_error = apply_filters( 'tutor_process_login_errors', $validation_error, $creds['user_login'], $creds['user_password'] );
437
438 if ( $validation_error->get_error_code() ) {
439 wp_send_json_error(
440 array(
441 'message' => $validation_error->get_error_message(),
442 )
443 );
444 }
445
446 if ( empty( $creds['user_login'] ) ) {
447 wp_send_json_error(
448 array(
449 'message' => __( 'Username is required.', 'tutor' ),
450 )
451 );
452 }
453
454 // On multisite, ensure user exists on current site, if not add them before allowing login.
455 if ( is_multisite() ) {
456 $user_data = get_user_by( is_email( $creds['user_login'] ) ? 'email' : 'login', $creds['user_login'] );
457
458 if ( $user_data && ! is_user_member_of_blog( $user_data->ID, get_current_blog_id() ) ) {
459 add_user_to_blog( get_current_blog_id(), $user_data->ID, 'customer' );
460 }
461 }
462
463 // Perform the login.
464 $user = wp_signon( apply_filters( 'tutor_login_credentials', $creds ), is_ssl() );
465
466 if ( is_wp_error( $user ) ) {
467 wp_send_json_error(
468 array(
469 'message' => $user->get_error_message(),
470 )
471 );
472 } else {
473 do_action( 'tutor_after_login_success', $user->ID );
474 // since 1.9.8 do enroll if guest attempt to enroll
475 if ( ! empty( $_POST['tutor_course_enroll_attempt'] ) && is_a( $user, 'WP_User' ) ) {
476 do_action( 'tutor_do_enroll_after_login_if_attempt', $_POST['tutor_course_enroll_attempt'], $user->ID );
477 }
478 wp_send_json_success(
479 array(
480 'redirect_to' => apply_filters( 'tutor_login_redirect_url', $redirect_to, $user ),
481 )
482 );
483 }
484 } catch ( \Exception $e ) {
485 do_action( 'tutor_login_failed' );
486 wp_send_json_error( apply_filters( 'login_errors', $e->getMessage() ) );
487 }
488 }
489
490 /**
491 * Create/Update announcement
492 *
493 * @since v.1.7.9
494 */
495 public function create_or_update_annoucement() {
496 tutor_utils()->checking_nonce();
497
498 $error = array();
499 $course_id = sanitize_text_field( $_POST['tutor_announcement_course'] );
500 $announcement_title = sanitize_text_field( $_POST['tutor_announcement_title'] );
501 $announcement_summary = sanitize_textarea_field( $_POST['tutor_announcement_summary'] );
502
503 // Check if user can manage this announcment
504 if ( ! tutor_utils()->can_user_manage( 'course', $course_id ) ) {
505 wp_send_json_error( array( 'message' => __( 'Access Denied', 'tutor' ) ) );
506 }
507
508 // set data and sanitize it
509 $form_data = array(
510 'post_type' => 'tutor_announcements',
511 'post_title' => $announcement_title,
512 'post_content' => $announcement_summary,
513 'post_parent' => $course_id,
514 'post_status' => 'publish',
515 );
516
517 if ( isset( $_POST['announcement_id'] ) ) {
518 $form_data['ID'] = sanitize_text_field( $_POST['announcement_id'] );
519 }
520
521 // validation message set
522 if ( empty( $form_data['post_parent'] ) ) {
523 $error['post_parent'] = __( 'Course name required', 'tutor' );
524
525 }
526
527 if ( empty( $form_data['post_title'] ) ) {
528 $error['post_title'] = __( 'Announcement title required', 'tutor' );
529 }
530
531 if ( empty( $form_data['post_content'] ) ) {
532 $error['post_content'] = __( 'Announcement summary required', 'tutor' );
533
534 }
535
536 if ( empty( $form_data['post_content'] ) ) {
537 $error['post_content'] = __( 'Announcement summary required', 'tutor' );
538
539 }
540
541 // If validation fails
542 if ( count( $error ) > 0 ) {
543 wp_send_json_error(
544 array(
545 'message' => __( 'All fields required!', 'tutor' ),
546 'fields' => $error,
547 )
548 );
549 }
550
551 // insert or update post
552 $post_id = wp_insert_post( $form_data );
553 if ( $post_id > 0 ) {
554 $announcement = get_post( $post_id );
555 $action_type = sanitize_textarea_field( $_POST['action_type'] );
556
557 do_action( 'tutor_announcements/after/save', $post_id, $announcement, $action_type );
558
559 $resp_message = $action_type == 'create' ? __( 'Announcement created successfully', 'tutor' ) : __( 'Announcement updated successfully', 'tutor' );
560 wp_send_json_success( array( 'message' => $resp_message ) );
561 }
562
563 wp_send_json_error( array( 'message' => __( 'Something Went Wrong!', 'tutor' ) ) );
564 }
565
566 /**
567 * Delete announcement
568 *
569 * @since v.1.7.9
570 */
571 public function delete_annoucement() {
572 $announcement_id = sanitize_text_field( $_POST['announcement_id'] );
573 tutor_utils()->checking_nonce();
574
575 if ( ! tutor_utils()->can_user_manage( 'announcement', $announcement_id ) ) {
576 wp_send_json_error( array( 'message' => __( 'Access Denied', 'tutor' ) ) );
577 }
578
579 $delete = wp_delete_post( $announcement_id );
580 if ( $delete ) {
581 wp_send_json_success( array( 'message' => __( 'Announcement deleted successfully', 'tutor' ) ) );
582 }
583
584 wp_send_json_error( array( 'message' => __( 'Announcement delete failed', 'tutor' ) ) );
585 }
586 }
587