From 67f82f95e6cbae5082bdb8bc0382f2c9155368f9 Mon Sep 17 00:00:00 2001 From: Sazedul Haque Date: Thu, 3 Dec 2026 13:40:57 +0600 Subject: [PATCH 1/2] Enforce instructor approval checks Filter instructor listings by approval status and prevent unapproved instructors from passing course eligibility checks. --- classes/Utils.php | 8 ++++++++ models/CourseModel.php | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/classes/Utils.php b/classes/Utils.php index d7a6d08214..ad0bd394ef 100644 --- a/classes/Utils.php +++ b/classes/Utils.php @@ -3319,6 +3319,9 @@ public function get_instructors_by_course( $course_id = 0 ) { ON ID = get_course.user_id AND get_course.meta_key = %s AND get_course.meta_value = %d + LEFT JOIN {$wpdb->usermeta} instructor_status + ON ID = instructor_status.user_id + AND instructor_status.meta_key = '_tutor_instructor_status' LEFT JOIN {$wpdb->usermeta} tutor_job_title ON ID = tutor_job_title.user_id AND tutor_job_title.meta_key = %s @@ -3328,6 +3331,7 @@ public function get_instructors_by_course( $course_id = 0 ) { LEFT JOIN {$wpdb->usermeta} tutor_photo ON ID = tutor_photo.user_id AND tutor_photo.meta_key = %s + WHERE instructor_status.meta_value = 'approved' ", '_tutor_instructor_course_id', $course_id, @@ -3351,6 +3355,9 @@ public function get_instructors_by_course( $course_id = 0 ) { ON _user.ID = course.post_author AND course.ID = %d AND course.post_type IN (%s, %s) + LEFT JOIN {$wpdb->usermeta} instructor_status + ON _user.ID = instructor_status.user_id + AND instructor_status.meta_key = '_tutor_instructor_status' LEFT JOIN {$wpdb->usermeta} tutor_job_title ON _user.ID = tutor_job_title.user_id AND tutor_job_title.meta_key = %s @@ -3360,6 +3367,7 @@ public function get_instructors_by_course( $course_id = 0 ) { LEFT JOIN {$wpdb->usermeta} tutor_photo ON _user.ID = tutor_photo.user_id AND tutor_photo.meta_key = %s + WHERE (instructor_status.meta_value = 'approved' OR instructor_status.meta_value IS NULL) ", $course_id, tutor()->course_post_type, diff --git a/models/CourseModel.php b/models/CourseModel.php index de58431157..6e49da9365 100644 --- a/models/CourseModel.php +++ b/models/CourseModel.php @@ -416,6 +416,11 @@ public static function is_main_instructor( $course_id, $user_id = 0 ) { return false; } + $instructor_status = get_user_meta( $user_id, '_tutor_instructor_status', true ); + if ( 'approved' !== $instructor_status ) { + return false; + } + return true; } From da82d53af6c685ba976d7a2a1a560fab79c5aaec Mon Sep 17 00:00:00 2001 From: Sazedul Haque Date: Thu, 3 Dec 2026 13:43:14 +0600 Subject: [PATCH 2/2] Update responses type for topic access denial Return the standard error message and forbidden status when users cannot manage a course or topic, or the topic does not belong to the course. --- classes/Course.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/classes/Course.php b/classes/Course.php index 0f20a0e78f..0f9a07c3be 100644 --- a/classes/Course.php +++ b/classes/Course.php @@ -2179,13 +2179,21 @@ public function tutor_save_topic() { // Validate if user can manage the topic. if ( ! tutor_utils()->can_user_manage( 'course', $course_id ) || ( $topic_id && ! tutor_utils()->can_user_manage( 'topic', $topic_id ) ) ) { - wp_send_json_error( array( 'message' => __( 'Access Denied', 'tutor' ) ) ); + $this->json_response( + tutor_utils()->error_message(), + null, + HttpHelper::STATUS_FORBIDDEN + ); } if ( $topic_id ) { $existing_topic = get_post( $topic_id ); if ( ! $existing_topic || tutor()->topics_post_type !== $existing_topic->post_type || (int) $existing_topic->post_parent !== $course_id ) { - wp_send_json_error( array( 'message' => __( 'Access Denied', 'tutor' ) ) ); + $this->json_response( + tutor_utils()->error_message(), + null, + HttpHelper::STATUS_FORBIDDEN + ); } }