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
2 changes: 1 addition & 1 deletion classes/Quiz.php
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ public function start_the_quiz() {
}

// Check & die if don't have quiz access.
QuizModel::has_quiz_access( $quiz_id, $course->id );
QuizModel::has_quiz_access( $quiz_id, $course->ID );

if ( ! self::has_supported_questions( $quiz_id ) ) {
wp_die( esc_html( self::unavailable_quiz_message() ) );
Expand Down
31 changes: 22 additions & 9 deletions classes/Reviews.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use Tutor\Core\Input;
use Tutor\Helpers\QueryHelper;
use Tutor\Helpers\UrlHelper;
use Tutor\Models\CourseModel;

/**
* Handle ratings related logics
*
Expand Down Expand Up @@ -52,19 +54,22 @@
public function delete_review() {
tutor_utils()->checking_nonce();

// Check if user is privileged.
if ( ! current_user_can( 'administrator' ) ) {
if ( ! User::is_admin() ) {
wp_send_json_error( array( 'message' => tutor_utils()->error_message() ) );
}

$review_id = Input::post( 'id', 0, Input::TYPE_INT );
$delete = self::delete( $review_id );
$comment = get_comment( $review_id );
if ( $comment->comment_type !== self::COURSE_RATING ) {

Check failure on line 63 in classes/Reviews.php

View workflow job for this annotation

GitHub Actions / WPCS

Use Yoda Condition checks, you must.
wp_send_json_error( array( 'message' => __( 'Invalid review ID.', 'tutor' ) ) );
}

if ( $delete ) {
wp_send_json_success();
} else {
wp_send_json_error( array( 'message' => __( 'Something went wrong!', 'tutor' ) ) );
$delete = self::delete( $review_id );
if ( ! $delete ) {
wp_send_json_error( array( 'message' => __( 'Failed to delete review.', 'tutor' ) ) );
}
exit;

wp_send_json_success( array( 'message' => __( 'Review deleted successfully.', 'tutor' ) ) );
}

/**
Expand Down Expand Up @@ -99,6 +104,11 @@
public function tutor_single_course_reviews_load_more() {
tutor_utils()->checking_nonce();

$course_id = Input::post( 'course_id', 0, Input::TYPE_INT );
if ( ! CourseModel::is_course_accessible( $course_id ) ) {
wp_send_json_error( array( 'message' => tutor_utils()->error_message( 'invalid_req' ) ) );
}

ob_start();
tutor_load_template( 'single.course.reviews' );
$html = ob_get_clean();
Expand Down Expand Up @@ -126,7 +136,10 @@
$status = Input::post( 'status' );

global $wpdb;
$wpdb->update( $wpdb->comments, array( 'comment_approved' => $status ), array( 'comment_ID' => $review_id ) );
$updated = $wpdb->update( $wpdb->comments, array( 'comment_approved' => $status ), array( 'comment_ID' => $review_id ) );
if ( ! $updated ) {
wp_send_json_error( array( 'message' => __( 'Failed to update review status', 'tutor' ) ) );
}

if ( 'approved' === $status ) {
do_action( 'tutor_course_review_approved', $review_id );
Expand Down
33 changes: 19 additions & 14 deletions classes/Shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,14 @@ function ( $id ) {
private function prepare_instructor_list( $current_page, $atts, $cat_ids = array(), $keyword = '' ) {

$default_pagination = tutor_utils()->get_option( 'pagination_per_page', 9 );
$limit = (int) sanitize_text_field( tutor_utils()->array_get( 'count', $atts, $default_pagination ) );
$page = $current_page - 1;
$rating_filter = Input::post( 'rating_filter', '' );
$limit = absint( sanitize_text_field( tutor_utils()->array_get( 'count', $atts, $default_pagination ) ) );
$limit = max( 1, $limit );

$current_page = max( 1, absint( $current_page ) );
$page = $current_page - 1;

$rating_filter = Input::post( 'rating_filter', '' );
$start = $limit * $page;

/**
* Sort by Relevant | New | Popular
Expand All @@ -311,8 +316,8 @@ private function prepare_instructor_list( $current_page, $atts, $cat_ids = array
*/
$short_by = Input::post( 'short_by', 'ASC' );

$instructors = tutor_utils()->get_instructors( $limit * $page, $limit, $keyword, '', '', $short_by, 'approved', $cat_ids, $rating_filter );
$instructors_count = tutor_utils()->get_instructors( $limit * $page, $limit, $keyword, '', '', $short_by, 'approved', $cat_ids, $rating_filter, true );
$instructors = tutor_utils()->get_instructors( $start, $limit, $keyword, '', '', $short_by, 'approved', $cat_ids, $rating_filter );
$instructors_count = tutor_utils()->get_instructors( $start, $limit, $keyword, '', '', $short_by, 'approved', $cat_ids, $rating_filter, true );

$layout = sanitize_text_field( tutor_utils()->array_get( 'layout', $atts, '' ) );
$layout = in_array( $layout, $this->instructor_layout ) ? $layout : tutor_utils()->get_option( 'instructor_list_layout', $this->instructor_layout[0] );
Expand Down Expand Up @@ -459,18 +464,18 @@ public function show_more() {
public function load_filtered_instructor() {
tutor_utils()->checking_nonce();

// phpcs:disable WordPress.Security.NonceVerification.Missing --nonce already verified
// phpcs:ignore WordPress.Security.NonceVerification.Missing --nonce already verified
$_post = tutor_sanitize_data( $_POST );
$current_page = (int) sanitize_text_field( tutor_utils()->array_get( 'current_page', $_post, 1 ) );
$keyword = (string) sanitize_text_field( tutor_utils()->array_get( 'keyword', $_post, '' ) );
$current_page = max( 1, Input::post( 'current_page', 1, Input::TYPE_INT ) );
$keyword = Input::post( 'keyword', '' );

// Prevent search by email address from public instructor list.
if ( strpos( $keyword, '@' ) !== false ) {
$keyword = '';
}

$category = (array) tutor_utils()->array_get( 'category', $_post, array() );
$category = array_filter(
$category,
function ( $cat ) {
return is_numeric( $cat );
}
);
$category = array_filter( $category, fn( $cat ) => is_numeric( $cat ) );

$data = $this->prepare_instructor_list( $current_page, $_post, $category, $keyword );

Expand Down
Loading