diff --git a/assets/react/lib/modules/instructor-review.js b/assets/react/lib/modules/instructor-review.js index 0650342b7a..0bec62aaa7 100644 --- a/assets/react/lib/modules/instructor-review.js +++ b/assets/react/lib/modules/instructor-review.js @@ -43,20 +43,20 @@ window.jQuery(document).ready($ => { course_id: course_id } - $.ajax({ - url: _tutorobject.ajaxurl, - type: 'POST', - dataType: 'json', - data: data, - success: function (res) { - if ( ! res.success ) { - console.warn('review pupup data clear error'); - } - }, - complete: function(){ - modal.removeClass('tutor-is-active'); - } - }); + $.ajax({ + url: _tutorobject.ajaxurl, + type: 'POST', + dataType: 'json', + data: data, + beforeSend: function () { + modal.removeClass('tutor-is-active'); + }, + success: function (res) { + if (!res.success) { + console.warn('review popup data clear error'); + } + } + }); }) $(document).on('click', '.tutor_submit_review_btn', function (e) { @@ -115,7 +115,7 @@ window.jQuery(document).ready($ => { }, success: function (res) { if ( ! res.success ) { - console.warn('review pupup data clear error'); + console.warn('review popup data clear error'); } } }); diff --git a/classes/Course.php b/classes/Course.php index acbb10bdae..5725b8bffc 100644 --- a/classes/Course.php +++ b/classes/Course.php @@ -857,8 +857,8 @@ public static function set_review_popup_data( $user_id, $course_id ) { if ( get_tutor_option( 'enable_course_review' ) ) { $rating = tutor_utils()->get_course_rating_by_user( $course_id, $user_id ); if ( ! $rating || ( empty( $rating->rating ) && empty( $rating->review ) ) ) { - $meta_key = User::REVIEW_POPUP_META . '_' . $course_id; - add_user_meta( $user_id, $meta_key, $course_id ); + $meta_key = User::get_review_popup_meta( $course_id ); + add_user_meta( $user_id, $meta_key, $course_id, true ); } } } @@ -873,7 +873,7 @@ public function popup_review_form() { if ( is_user_logged_in() ) { $user_id = get_current_user_id(); $course_id = get_the_ID(); - $meta_key = User::REVIEW_POPUP_META . '_' . $course_id; + $meta_key = User::get_review_popup_meta( $course_id ); $review_course_id = (int) get_user_meta( $user_id, $meta_key, true ); if ( is_single() && $course_id === $review_course_id ) { @@ -897,7 +897,7 @@ public function clear_review_popup_data() { $course_id = Input::post( 'course_id', 0, Input::TYPE_INT ); if ( $course_id ) { - $meta_key = User::REVIEW_POPUP_META . '_' . $course_id; + $meta_key = User::get_review_popup_meta( $course_id ); delete_user_meta( $user_id, $meta_key, $course_id ); } diff --git a/classes/User.php b/classes/User.php index 759ff98293..edb0eb6d82 100644 --- a/classes/User.php +++ b/classes/User.php @@ -64,6 +64,19 @@ public function __construct( $register_hooks = true ) { add_action( 'admin_init', array( $this, 'hide_notices' ) ); } + /** + * Get meta key name for review popup. + * + * @since 2.4.0 + * + * @param int $course_id course id. + * + * @return string user meta key name. + */ + public static function get_review_popup_meta( $course_id ) { + return self::REVIEW_POPUP_META . '_' . $course_id; + } + /** * Check user has provided role. *