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
53 changes: 31 additions & 22 deletions classes/Course.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,12 @@
*
* @since v.1.6.6
*/
add_action( 'deleted_post', array( new CourseModel(), 'delete_course_data' ) );
add_action(
'deleted_post',
function ( $post_id ) {
( new CourseModel() )->delete_course_data( $post_id );
}
);

/**
* Delete course data after deleted course
Expand Down Expand Up @@ -323,7 +328,7 @@
global $wp_query;
$course_coming_soon_enabled = (int) get_post_meta( $content->ID, '_tutor_course_enable_coming_soon', true );
$is_instructor = tutor_utils()->is_instructor_of_this_course( get_current_user_id(), $content->ID, true );
if ( ! CourseModel::get_post_types( $content ) || current_user_can( 'administrator' ) || $is_instructor || $course_coming_soon_enabled ) {

Check failure on line 331 in classes/Course.php

View workflow job for this annotation

GitHub Actions / WPCS

Capabilities should be used instead of roles. Found "administrator" in function call to current_user_can()
return $content;
}

Expand Down Expand Up @@ -355,12 +360,12 @@
*
* @since 4.0.0
*
* @param bool $required Whether the password is required.
* @param WP_Post $post The post object.
* @param bool $required Whether the password is required.
* @param \WP_Post $post The post object.
*
* @return bool false if the current user is enrolled, original value otherwise.
*/
public function bypass_password_for_enrolled( $required, $post ) {
public function bypass_password_for_enrolled( $required, \WP_Post $post ) {
if ( ! $required ) {
return $required;
}
Expand Down Expand Up @@ -654,7 +659,7 @@
} else {
$errors['pricing'] = __( 'Invalid product', 'tutor' );
}
} else {

Check failure on line 662 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 @@ -791,7 +796,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 799 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 @@ -1098,7 +1103,8 @@
'course_target_audience' => 'sanitize_textarea_field',
'course_material_includes' => 'sanitize_textarea_field',
'course_requirements' => 'sanitize_textarea_field',
)
),
true
);

$course_id = (int) $params['course_id'];
Expand Down Expand Up @@ -1254,13 +1260,16 @@
$topic_contents = tutor_utils()->get_course_contents_by_topic( $post->ID, -1 );

if ( $topic_contents->have_posts() ) {
foreach ( $topic_contents->get_posts() as $post ) {
if ( tutor()->quiz_post_type === $post->post_type ) {
$questions = tutor_utils()->get_questions_by_quiz( $post->ID );
$post->total_question = is_array( $questions ) ? count( $questions ) : 0;
foreach ( $topic_contents->get_posts() as $content ) {
if ( tutor()->quiz_post_type === $content->post_type ) {
$questions = tutor_utils()->get_questions_by_quiz( $content->ID );
$content = (object) array_merge(
(array) $content,
array( 'total_question' => is_array( $questions ) ? count( $questions ) : 0 )
);
}

array_push( $current_topic['contents'], $post );
array_push( $current_topic['contents'], $content );
}
}

Expand Down Expand Up @@ -1361,10 +1370,10 @@
if ( $video_intro ) {
$source = $video_intro['source'] ?? '';
if ( 'html5' === $source ) {
$poster_url = wp_get_attachment_url( $video['poster'] ?? 0 );
$source_html5 = wp_get_attachment_url( $video['source_video_id'] ?? 0 );
$video['poster_url'] = $poster_url;
$video['source_html5'] = $source_html5;
$poster_url = wp_get_attachment_url( $video_intro['poster'] ?? 0 );
$source_html5 = wp_get_attachment_url( $video_intro['source_video_id'] ?? 0 );
$video_intro['poster_url'] = $poster_url;
$video_intro['source_html5'] = $source_html5;
}
}

Expand Down Expand Up @@ -1521,7 +1530,7 @@

if ( isset( $default_data['current_user']['data']['id'] ) ) {
$tutor_user = tutor_utils()->get_tutor_user( $default_data['current_user']['data']['id'] );
$default_data['current_user']['data']['tutor_profile_photo_url'] = $tutor_user->tutor_profile_photo_url;
$default_data['current_user']['data']['tutor_profile_photo_url'] = is_object( $tutor_user ) ? $tutor_user->tutor_profile_photo_url : '';
}

/**
Expand Down Expand Up @@ -2212,7 +2221,7 @@
} else {
CourseModel::mark_course_as_completed( $course_id, $user_id );
// Set temporary identifier to show review pop up.
self::set_review_popup_data( $user_id, $course_id, $permalink );
self::set_review_popup_data( $user_id, $course_id );

wp_safe_redirect( $permalink );
exit;
Expand Down Expand Up @@ -2411,7 +2420,7 @@
/**
* Only admin can change main author
*/
if ( $courses_post_type === $post_type && ! current_user_can( 'administrator' ) ) {

Check failure on line 2423 in classes/Course.php

View workflow job for this annotation

GitHub Actions / WPCS

Capabilities should be used instead of roles. Found "administrator" in function call to current_user_can()
global $wpdb;
$post_ID = (int) tutor_utils()->avalue_dot( 'ID', $postarr );
$post_author = (int) $wpdb->get_var( $wpdb->prepare( "SELECT post_author FROM {$wpdb->posts} WHERE ID = %d ", $post_ID ) );
Expand Down Expand Up @@ -2616,7 +2625,7 @@
* @return string
*/
public function enable_disable_material_includes( $html ) {
$disable_option = ! (bool) get_tutor_option( 'enable_course_material', true, true );
$disable_option = ! (bool) get_tutor_option( 'enable_course_material', true );
if ( $disable_option ) {
return '';
}
Expand Down Expand Up @@ -2752,9 +2761,9 @@
if ( ! $hide_course_from_shop_page ) {
return;
}
add_action( 'woocommerce_product_query', array( $this, 'filter_woocommerce_product_query' ) );
add_filter( 'edd_downloads_query', array( $this, 'filter_edd_downloads_query' ), 10, 2 );
add_action( 'pre_get_posts', array( $this, 'filter_archive_meta_query' ), 1 );
add_filter( 'woocommerce_product_query', array( $this, 'filter_woocommerce_product_query' ) );
add_filter( 'edd_downloads_query', array( $this, 'filter_edd_downloads_query' ), 10 );
add_filter( 'pre_get_posts', array( $this, 'filter_archive_meta_query' ), 1 );
}


Expand Down Expand Up @@ -2888,7 +2897,7 @@
}

$completed_lessons = tutor_utils()->get_completed_lesson_count_by_course( $course_id, $user_id );
$total_lessons = tutor_utils()->get_lesson_count_by_course( $course_id );
$total_lessons = tutor_utils()->get_lesson_count_by_course( $course_id ); // @phpstan-ignore method.notFound

if ( $completed_lessons < $total_lessons ) {
return __( 'Complete all lessons to mark this course as complete', 'tutor' );
Expand Down Expand Up @@ -3108,7 +3117,7 @@
*
* @param integer $course_id course ID.
* @param integer $user_id user ID.
*
*
* @return void
*/
public function enroll_after_login_if_attempt( int $course_id, int $user_id ) {
Expand Down
3 changes: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
parameters:
level: 3
scanDirectories:
- ../tutor-pro
- ../woocommerce
paths:
- .
excludePaths:
Expand Down
Loading