| 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 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Handle ajax request for deleting review |
| 35 |
* |
| 36 |
* @since v2.0.0 |
| 37 |
*/ |
| 38 |
public function delete_review() { |
| 39 |
tutor_utils()->checking_nonce(); |
| 40 |
$review_id = isset( $_POST['id'] ) ? sanitize_text_field( $_POST['id'] ) : ''; |
| 41 |
$delete = self::delete( $review_id ); |
| 42 |
wp_send_json( $delete ); |
| 43 |
exit; |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Delete review |
| 48 |
* |
| 49 |
* @param int $id review id required. |
| 50 |
* @return bool true or false. |
| 51 |
* @since v2.0.0 |
| 52 |
*/ |
| 53 |
public static function delete( int $id ): bool { |
| 54 |
$id = sanitize_text_field( $id ); |
| 55 |
global $wpdb; |
| 56 |
$comment_table = $wpdb->comments; |
| 57 |
$delete = $wpdb->delete( |
| 58 |
$comment_table, |
| 59 |
array( |
| 60 |
'comment_ID' => $id, |
| 61 |
) |
| 62 |
); |
| 63 |
return $delete ? true : false; |
| 64 |
} |
| 65 |
|
| 66 |
public function tutor_single_course_reviews_load_more() { |
| 67 |
tutor_utils()->checking_nonce(); |
| 68 |
|
| 69 |
ob_start(); |
| 70 |
tutor_load_template( 'single.course.reviews' ); |
| 71 |
$html = ob_get_clean(); |
| 72 |
|
| 73 |
wp_send_json_success( array('html' => $html) ); |
| 74 |
} |
| 75 |
} |
| 76 |
|