Addons.php
4 years ago
Admin.php
4 years ago
Ajax.php
4 years ago
Announcements.php
4 years ago
Assets.php
4 years ago
Backend_Page_Trait.php
4 years ago
Course.php
4 years ago
Course_Filter.php
4 years ago
Course_List.php
4 years ago
Course_Settings_Tabs.php
4 years ago
Course_Widget.php
4 years ago
Custom_Validation.php
4 years ago
Dashboard.php
4 years ago
FormHandler.php
4 years ago
Frontend.php
4 years ago
Gutenberg.php
4 years ago
Input.php
4 years ago
Instructor.php
4 years ago
Instructors_List.php
4 years ago
Lesson.php
4 years ago
Options_V2.php
4 years ago
Post_types.php
4 years ago
Private_Course_Access.php
4 years ago
Q_and_A.php
4 years ago
Question_Answers_List.php
4 years ago
Quiz.php
4 years ago
Quiz_Attempts_List.php
4 years ago
RestAPI.php
4 years ago
Reviews.php
4 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
4 years ago
Theme_Compatibility.php
5 years ago
Tools.php
4 years ago
Tools_V2.php
4 years ago
Tutor.php
4 years ago
TutorEDD.php
4 years ago
Tutor_Base.php
5 years ago
Tutor_List_Table.php
4 years ago
Tutor_Setup.php
4 years ago
Upgrader.php
4 years ago
User.php
4 years ago
Utils.php
4 years ago
Video_Stream.php
4 years ago
Withdraw.php
4 years ago
Withdraw_Requests_List.php
4 years ago
WooCommerce.php
4 years ago
Reviews.php
100 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Tutor Ratings |
| 4 | * |
| 5 | * @package Ratings |
| 6 | * @since v2.0.0 |
| 7 | */ |
| 8 | |
| 9 | namespace TUTOR; |
| 10 | |
| 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | exit; |
| 13 | } |
| 14 | /** |
| 15 | * Handle ratings related logics |
| 16 | */ |
| 17 | class Reviews { |
| 18 | |
| 19 | /** |
| 20 | * Handle actions & dependencies |
| 21 | * |
| 22 | * @since v2.0.0 |
| 23 | */ |
| 24 | public function __construct() { |
| 25 | /** |
| 26 | * Delete reviews action |
| 27 | */ |
| 28 | add_action( 'wp_ajax_tutor_delete_review', array( $this, 'delete_review' ) ); |
| 29 | add_action( 'wp_ajax_tutor_single_course_reviews_load_more', array($this, 'tutor_single_course_reviews_load_more') ); |
| 30 | add_action( 'wp_ajax_nopriv_tutor_single_course_reviews_load_more', array($this, 'tutor_single_course_reviews_load_more') ); |
| 31 | add_action( 'wp_ajax_tutor_change_review_status', array($this, 'tutor_change_review_status') ); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Handle ajax request for deleting review |
| 36 | * |
| 37 | * @since v2.0.0 |
| 38 | */ |
| 39 | public function delete_review() { |
| 40 | tutor_utils()->checking_nonce(); |
| 41 | $review_id = isset( $_POST['id'] ) ? sanitize_text_field( $_POST['id'] ) : ''; |
| 42 | $delete = self::delete( $review_id ); |
| 43 | |
| 44 | if($delete) { |
| 45 | wp_send_json_success(); |
| 46 | } else { |
| 47 | wp_send_json_error(array('message' => __('Something went wrong!', 'tutor'))); |
| 48 | } |
| 49 | exit; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Delete review |
| 54 | * |
| 55 | * @param int $id review id required. |
| 56 | * @return bool true or false. |
| 57 | * @since v2.0.0 |
| 58 | */ |
| 59 | public static function delete( int $id ): bool { |
| 60 | $id = sanitize_text_field( $id ); |
| 61 | global $wpdb; |
| 62 | $comment_table = $wpdb->comments; |
| 63 | $delete = $wpdb->delete( |
| 64 | $comment_table, |
| 65 | array( |
| 66 | 'comment_ID' => $id, |
| 67 | ) |
| 68 | ); |
| 69 | return $delete ? true : false; |
| 70 | } |
| 71 | |
| 72 | public function tutor_single_course_reviews_load_more() { |
| 73 | tutor_utils()->checking_nonce(); |
| 74 | |
| 75 | ob_start(); |
| 76 | tutor_load_template( 'single.course.reviews' ); |
| 77 | $html = ob_get_clean(); |
| 78 | |
| 79 | wp_send_json_success( array('html' => $html) ); |
| 80 | } |
| 81 | |
| 82 | public function tutor_change_review_status(){ |
| 83 | |
| 84 | tutor_utils()->checking_nonce(); |
| 85 | |
| 86 | if(!current_user_can( 'manage_options' )) { |
| 87 | wp_send_json_error( array('message' => __('Only admin can change review status', 'tutor')) ); |
| 88 | exit; |
| 89 | } |
| 90 | |
| 91 | $review_id = (int)$_POST['id']; |
| 92 | $status = sanitize_text_field( $_POST['status'] ); |
| 93 | |
| 94 | global $wpdb; |
| 95 | $wpdb->update($wpdb->comments, array('comment_approved'=>$status), array('comment_ID'=>$review_id)); |
| 96 | |
| 97 | wp_send_json_success(); |
| 98 | } |
| 99 | } |
| 100 |