Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions classes/Course.php
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@
* Validate price for course create
*
* @since 3.0.0
* @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.
Expand All @@ -632,15 +633,21 @@
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' );
}
}
}
Expand All @@ -652,9 +659,10 @@
* Validate WC product author
*
* @since 4.2.2
* @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.
* @param int $course_id course id. Pass 0 when the course does not exist yet.
*
* @return bool
*/
Expand All @@ -667,6 +675,9 @@
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;
Expand Down Expand Up @@ -715,7 +726,7 @@
} else {
$errors['pricing'] = __( 'Invalid product', 'tutor' );
}
} else {

Check failure on line 729 in classes/Course.php

View workflow job for this annotation

GitHub Actions / WPCS

If control structure block found as the only statement within an "else" block. Use elseif instead.
/**
* If user does not select WC product
* Then automatic WC product will be create name with course title.
Expand Down Expand Up @@ -852,7 +863,7 @@
update_post_meta( $post_id, self::COURSE_PRICE_TYPE_META, $params['pricing']['type'] );
}
} catch ( \Throwable $th ) {
throw new \Exception( $th->getMessage() );

Check failure on line 866 in classes/Course.php

View workflow job for this annotation

GitHub Actions / WPCS

All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$th'.
}
}

Expand Down Expand Up @@ -1089,7 +1100,7 @@
public function ajax_create_course() {
tutor_utils()->check_nonce();

$course_id = intval( wp_unslash( $_POST['ID'] ?? 0 ) );

Check failure on line 1103 in classes/Course.php

View workflow job for this annotation

GitHub Actions / WPCS

Processing form data without nonce verification.
$this->check_access( $course_id ); // Check user cap for the given id before processing.

$params = Input::sanitize_array(
Expand Down
Loading