Skip to content
Open
Show file tree
Hide file tree
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
12 changes: 10 additions & 2 deletions classes/Course.php
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@
} else {
$errors['pricing'] = __( 'Invalid product', 'tutor' );
}
} else {

Check failure on line 718 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 +852,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 855 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 +1089,7 @@
public function ajax_create_course() {
tutor_utils()->check_nonce();

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

Check failure on line 1092 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 Expand Up @@ -2179,13 +2179,21 @@

// 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
);
}
}

Expand Down
8 changes: 8 additions & 0 deletions classes/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,7 @@
$user_id = $this->get_user_id( $user_id );

// Delete Quiz submissions.
$attempts = \Tutor\Models\QuizModel::get_quiz_attempts_by_course_ids( $start = 0, $limit = 99999999, $course_ids = array( $course_id ), $search_filter = '', $course_filter = '', $date_filter = '', $order_filter = '', $user_id = $user_id, false, true );

Check failure on line 1339 in classes/Utils.php

View workflow job for this annotation

GitHub Actions / WPCS

Assignments must be the first block of code on a line

if ( is_array( $attempts ) ) {
$attempt_ids = array_map(
Expand Down Expand Up @@ -1514,7 +1514,7 @@
ON topic.ID = items.post_parent
WHERE topic.post_parent = %d
AND items.post_status = %s
" . ( $post_type ? " AND items.post_type='{$post_type}' " : '' ) . '

Check failure on line 1517 in classes/Utils.php

View workflow job for this annotation

GitHub Actions / WPCS

Use placeholders and $wpdb->prepare(); found :

Check failure on line 1517 in classes/Utils.php

View workflow job for this annotation

GitHub Actions / WPCS

Use placeholders and $wpdb->prepare(); found interpolated variable {$post_type} at " AND items.post_type='{$post_type}' "

Check failure on line 1517 in classes/Utils.php

View workflow job for this annotation

GitHub Actions / WPCS

Use placeholders and $wpdb->prepare(); found ?

Check failure on line 1517 in classes/Utils.php

View workflow job for this annotation

GitHub Actions / WPCS

Use placeholders and $wpdb->prepare(); found $post_type
ORDER BY topic.menu_order ASC,
items.menu_order ASC;
',
Expand Down Expand Up @@ -2147,8 +2147,8 @@
ON user.ID = posts.post_author
WHERE posts.post_type = %s
AND posts.post_status = %s
{$course_query}

Check failure on line 2150 in classes/Utils.php

View workflow job for this annotation

GitHub Actions / WPCS

Use placeholders and $wpdb->prepare(); found interpolated variable {$course_query} at {$course_query}

{$date_query}

Check failure on line 2151 in classes/Utils.php

View workflow job for this annotation

GitHub Actions / WPCS

Use placeholders and $wpdb->prepare(); found interpolated variable {$date_query} at {$date_query}

AND (user.display_name LIKE %s OR user.user_email = %s OR user.user_login LIKE %s)
GROUP BY post_author
{$order_query}
Expand Down Expand Up @@ -3319,6 +3319,9 @@
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
Expand All @@ -3328,6 +3331,7 @@
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,
Expand All @@ -3351,6 +3355,9 @@
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
Expand All @@ -3360,6 +3367,7 @@
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,
Expand Down
5 changes: 5 additions & 0 deletions models/CourseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Loading