From b3d195925e029543550bcf5b9849ee116bfa5b84 Mon Sep 17 00:00:00 2001 From: Sadman Soumique Date: Tue, 1 Dec 2026 14:03:22 +0600 Subject: [PATCH 1/3] Enhance course product validation to restrict unauthorized WC products --- classes/Course.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/classes/Course.php b/classes/Course.php index 0f20a0e78f..870e6949c7 100644 --- a/classes/Course.php +++ b/classes/Course.php @@ -615,6 +615,7 @@ public function setup_course_categories_tags( $post_id, $params ) { * Validate price for course create * * @since 3.0.0 + * @since 4.2.3 Reject WC products the current user is not authorized to use. * * @param array $params array of params. * @param array $errors array of errors. @@ -632,15 +633,21 @@ public function validate_price( $params, &$errors ) { if ( self::PRICE_TYPE_PAID === $type ) { $monetize_by = tutor_utils()->get_option( 'monetize_by' ); if ( 'wc' === $monetize_by ) { - $product_id = (int) isset( $params['pricing']['product_id'] ) ? $params['pricing']['product_id'] : 0; + $product_id = isset( $params['pricing']['product_id'] ) ? (int) $params['pricing']['product_id'] : 0; // $product_id = 0 then new WC product will be created. if ( $product_id ) { $product = wc_get_product( $product_id ); if ( is_a( $product, 'WC_Product' ) ) { + if ( ! $this->is_valid_wc_product_author( $product_id, 0 ) ) { + $errors['pricing'] = __( 'You are not authorized to use this product', 'tutor' ); + } + $is_linked_with_course = tutor_utils()->product_belongs_with_course( $product_id ); if ( $is_linked_with_course ) { $errors['pricing'] = __( 'Product already linked with course', 'tutor' ); } + } else { + $errors['pricing'] = __( 'Invalid product', 'tutor' ); } } } @@ -652,9 +659,10 @@ public function validate_price( $params, &$errors ) { * Validate WC product author * * @since 4.2.2 + * @since 4.2.3 Support create flows with $course_id = 0 (owner-only). * * @param int $product_id product id. - * @param int $course_id course id. + * @param int $course_id course id. Pass 0 when the course does not exist yet. * * @return bool */ @@ -667,6 +675,9 @@ public function is_valid_wc_product_author( $product_id, $course_id ) { if ( $product_author === $current_user_id ) { return true; } + if ( ! $course_id ) { + return false; + } $course_author = (int) get_post_field( 'post_author', $course_id ); if ( $product_author === $course_author && tutor_utils()->is_instructor_of_this_course( $current_user_id, $course_id ) ) { return true; From 89fd8a9193fc2dd5b815eb326a9ef753ef9dc218 Mon Sep 17 00:00:00 2001 From: Sadman Soumique Date: Tue, 1 Dec 2026 17:51:59 +0600 Subject: [PATCH 2/3] Update course validation documentation for versioning consistency --- classes/Course.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/Course.php b/classes/Course.php index 870e6949c7..1ef357dce2 100644 --- a/classes/Course.php +++ b/classes/Course.php @@ -659,7 +659,7 @@ public function validate_price( $params, &$errors ) { * Validate WC product author * * @since 4.2.2 - * @since 4.2.3 Support create flows with $course_id = 0 (owner-only). + * @since 4.3.0 Support create flows with $course_id = 0 (owner-only). * * @param int $product_id product id. * @param int $course_id course id. Pass 0 when the course does not exist yet. From 370558988c7d45e7957308f59e7a3d139cd59e4c Mon Sep 17 00:00:00 2001 From: Sadman Soumique Date: Tue, 1 Dec 2026 17:54:18 +0600 Subject: [PATCH 3/3] Update course validation documentation to reflect version 4.3.0 changes --- classes/Course.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/Course.php b/classes/Course.php index 1ef357dce2..0bd6a370b8 100644 --- a/classes/Course.php +++ b/classes/Course.php @@ -615,7 +615,7 @@ public function setup_course_categories_tags( $post_id, $params ) { * Validate price for course create * * @since 3.0.0 - * @since 4.2.3 Reject WC products the current user is not authorized to use. + * @since 4.3.0 Reject WC products the current user is not authorized to use. * * @param array $params array of params. * @param array $errors array of errors.