| @@ -207,14 +207,9 @@ | ||
| 207 | 207 | * Delete course data after deleted course |
| 208 | 208 | * |
| 209 | 209 | * @since v.1.6.6 |
| 210 | 210 | */ |
| 211 | - add_action( | |
| 212 | - 'deleted_post', | |
| 213 | - function ( $post_id ) { | |
| 214 | - ( new CourseModel() )->delete_course_data( $post_id ); | |
| 215 | - } | |
| 216 | - ); | |
| 211 | + add_action( 'deleted_post', array( new CourseModel(), 'delete_course_data' ) ); | |
| 217 | 212 | |
| 218 | 213 | /** |
| 219 | 214 | * Delete course data after deleted course |
| 220 | 215 | * |
| @@ -359,10 +354,10 @@ | ||
| 359 | 354 | * Bypass password protection for enrolled users. |
| 360 | 355 | * |
| 361 | 356 | * @since 4.0.0 |
| 362 | 357 | * |
| 363 | - * @param bool $required Whether the password is required. | |
| 364 | - * @param \WP_Post $post The post object. | |
| 358 | + * @param bool $required Whether the password is required. | |
| 359 | + * @param WP_Post $post The post object. | |
| 365 | 360 | * |
| 366 | 361 | * @return bool false if the current user is enrolled, original value otherwise. |
| 367 | 362 | */ |
| 368 | 363 | public function bypass_password_for_enrolled( $required, $post ) { |
| @@ -1102,10 +1097,9 @@ | ||
| 1102 | 1097 | 'course_benefits' => 'sanitize_textarea_field', |
| 1103 | 1098 | 'course_target_audience' => 'sanitize_textarea_field', |
| 1104 | 1099 | 'course_material_includes' => 'sanitize_textarea_field', |
| 1105 | 1100 | 'course_requirements' => 'sanitize_textarea_field', |
| 1106 | - ), | |
| 1107 | - true | |
| 1101 | + ) | |
| 1108 | 1102 | ); |
| 1109 | 1103 | |
| 1110 | 1104 | $course_id = (int) $params['course_id']; |
| 1111 | 1105 | if ( ! $course_id ) { |
| @@ -1259,18 +1253,15 @@ | ||
| 1259 | 1253 | |
| 1260 | 1254 | $topic_contents = tutor_utils()->get_course_contents_by_topic( $post->ID, -1 ); |
| 1261 | 1255 | |
| 1262 | 1256 | if ( $topic_contents->have_posts() ) { |
| 1263 | - foreach ( $topic_contents->get_posts() as $content ) { | |
| 1264 | - if ( tutor()->quiz_post_type === $content->post_type ) { | |
| 1265 | - $questions = tutor_utils()->get_questions_by_quiz( $content->ID ); | |
| 1266 | - $content = (object) array_merge( | |
| 1267 | - (array) $content, | |
| 1268 | - array( 'total_question' => is_array( $questions ) ? count( $questions ) : 0 ) | |
| 1269 | - ); | |
| 1257 | + foreach ( $topic_contents->get_posts() as $post ) { | |
| 1258 | + if ( tutor()->quiz_post_type === $post->post_type ) { | |
| 1259 | + $questions = tutor_utils()->get_questions_by_quiz( $post->ID ); | |
| 1260 | + $post->total_question = is_array( $questions ) ? count( $questions ) : 0; | |
| 1270 | 1261 | } |
| 1271 | 1262 | |
| 1272 | - array_push( $current_topic['contents'], $content ); | |
| 1263 | + array_push( $current_topic['contents'], $post ); | |
| 1273 | 1264 | } |
| 1274 | 1265 | } |
| 1275 | 1266 | |
| 1276 | 1267 | $current_topic = apply_filters( 'tutor_filter_course_content', $current_topic ); |
| @@ -1369,12 +1360,12 @@ | ||
| 1369 | 1360 | $video_intro = get_post_meta( $course_id, '_video', true ); |
| 1370 | 1361 | if ( $video_intro ) { |
| 1371 | 1362 | $source = $video_intro['source'] ?? ''; |
| 1372 | 1363 | if ( 'html5' === $source ) { |
| 1373 | - $poster_url = wp_get_attachment_url( $video_intro['poster'] ?? 0 ); | |
| 1374 | - $source_html5 = wp_get_attachment_url( $video_intro['source_video_id'] ?? 0 ); | |
| 1375 | - $video_intro['poster_url'] = $poster_url; | |
| 1376 | - $video_intro['source_html5'] = $source_html5; | |
| 1364 | + $poster_url = wp_get_attachment_url( $video['poster'] ?? 0 ); | |
| 1365 | + $source_html5 = wp_get_attachment_url( $video['source_video_id'] ?? 0 ); | |
| 1366 | + $video['poster_url'] = $poster_url; | |
| 1367 | + $video['source_html5'] = $source_html5; | |
| 1377 | 1368 | } |
| 1378 | 1369 | } |
| 1379 | 1370 | |
| 1380 | 1371 | $course = get_post( $course_id, ARRAY_A ); |
| @@ -1383,23 +1374,13 @@ | ||
| 1383 | 1374 | } |
| 1384 | 1375 | |
| 1385 | 1376 | $editors = tutor_utils()->get_editor_list( $course_id ); |
| 1386 | 1377 | |
| 1387 | - /** | |
| 1388 | - * Replaced the post_author with current user id if post_author value is 0. | |
| 1389 | - * | |
| 1390 | - * @since 4.0.7 | |
| 1391 | - */ | |
| 1392 | - $post_author = (int) $course['post_author']; | |
| 1393 | - if ( 0 === $post_author && $course_id > 0 ) { | |
| 1394 | - $post_author = get_current_user_id(); | |
| 1395 | - } | |
| 1396 | - | |
| 1397 | 1378 | $data = array( |
| 1398 | 1379 | 'editors' => array_values( $editors ), |
| 1399 | 1380 | 'editor_used' => tutor_utils()->get_editor_used( $course_id ), |
| 1400 | 1381 | 'preview_link' => get_preview_post_link( $course_id ), |
| 1401 | - 'post_author' => tutor_utils()->get_tutor_user( $post_author ), | |
| 1382 | + 'post_author' => tutor_utils()->get_tutor_user( $course['post_author'] ), | |
| 1402 | 1383 | 'course_categories' => wp_get_post_terms( $course_id, CourseModel::COURSE_CATEGORY ), |
| 1403 | 1384 | 'course_tags' => wp_get_post_terms( $course_id, CourseModel::COURSE_TAG ), |
| 1404 | 1385 | 'thumbnail_id' => get_post_meta( $course_id, '_thumbnail_id', true ), |
| 1405 | 1386 | 'thumbnail' => get_the_post_thumbnail_url( $course_id ), |
| @@ -1539,9 +1520,9 @@ | ||
| 1539 | 1520 | $default_data = ( new Assets( false ) )->get_default_localized_data(); |
| 1540 | 1521 | |
| 1541 | 1522 | if ( isset( $default_data['current_user']['data']['id'] ) ) { |
| 1542 | 1523 | $tutor_user = tutor_utils()->get_tutor_user( $default_data['current_user']['data']['id'] ); |
| 1543 | - $default_data['current_user']['data']['tutor_profile_photo_url'] = is_object( $tutor_user ) ? $tutor_user->tutor_profile_photo_url : ''; | |
| 1524 | + $default_data['current_user']['data']['tutor_profile_photo_url'] = $tutor_user->tutor_profile_photo_url; | |
| 1544 | 1525 | } |
| 1545 | 1526 | |
| 1546 | 1527 | /** |
| 1547 | 1528 | * Localized only options to protect sensitive info like API keys. |
| @@ -1768,13 +1749,13 @@ | ||
| 1768 | 1749 | $topic_id = (int) isset( $sorting_order[0], $sorting_order[0]['topic_id'] ) ? $sorting_order[0]['topic_id'] : 0; |
| 1769 | 1750 | $course_id = wp_get_post_parent_id( $topic_id ); |
| 1770 | 1751 | |
| 1771 | 1752 | if ( ! $topic_id || ! $course_id ) { |
| 1772 | - $this->response_bad_request( tutor_utils()->error_message( 'invalid_req' ) ); | |
| 1753 | + wp_send_json_error( tutor_utils()->error_message( 'invalid_req' ) ); | |
| 1773 | 1754 | } |
| 1774 | 1755 | |
| 1775 | - if ( ! tutor_utils()->can_user_manage( 'course', $course_id ) && ! User::is_admin() ) { | |
| 1776 | - $this->json_response( tutor_utils()->error_message(), null, HttpHelper::STATUS_UNAUTHORIZED ); | |
| 1756 | + if ( ! tutor_utils()->can_user_manage( 'course', $course_id ) || ! User::is_admin() ) { | |
| 1757 | + wp_send_json_error( tutor_utils()->error_message() ); | |
| 1777 | 1758 | } |
| 1778 | 1759 | |
| 1779 | 1760 | if ( Input::has( 'content_parent' ) ) { |
| 1780 | 1761 | $content_parent = Input::post( 'content_parent', array(), Input::TYPE_ARRAY ); |
| @@ -1788,9 +1769,9 @@ | ||
| 1788 | 1769 | |
| 1789 | 1770 | // Save course content order. |
| 1790 | 1771 | $this->save_course_content_order( $sorting_order ); |
| 1791 | 1772 | |
| 1792 | - $this->response_success( __( 'Course content order updated successfully!', 'tutor' ) ); | |
| 1773 | + wp_send_json_success(); | |
| 1793 | 1774 | } |
| 1794 | 1775 | |
| 1795 | 1776 | /** |
| 1796 | 1777 | * Restrict new student entry |
| @@ -1975,9 +1956,8 @@ | ||
| 1975 | 1956 | 'source_embedded' => 'wp_kses_post', |
| 1976 | 1957 | ), |
| 1977 | 1958 | true |
| 1978 | 1959 | ); |
| 1979 | - $video = tutor_utils()->filter_video_meta( $video ); | |
| 1980 | 1960 | $video_source = tutor_utils()->array_get( 'source', $video ); |
| 1981 | 1961 | if ( -1 !== $video_source ) { |
| 1982 | 1962 | update_post_meta( $post_ID, '_video', $video ); |
| 1983 | 1963 | } elseif ( ! tutor_is_rest() ) { |
| @@ -1987,23 +1967,12 @@ | ||
| 1987 | 1967 | |
| 1988 | 1968 | /** |
| 1989 | 1969 | * Adding author to instructor automatically |
| 1990 | 1970 | */ |
| 1991 | - $requested_author_id = Input::post( 'post_author_override', 0, Input::TYPE_INT ); | |
| 1992 | 1971 | |
| 1993 | - /** | |
| 1994 | - * Only accept the requested author override if it targets a real,approved instructor or admin | |
| 1995 | - * | |
| 1996 | - * @since 4.0.4 | |
| 1997 | - */ | |
| 1998 | - $author_id = $post->post_author; | |
| 1999 | - if ( $requested_author_id && ( User::is_admin() || User::is_instructor() ) ) { | |
| 2000 | - if ( User::is_admin( $requested_author_id ) || User::is_instructor( $requested_author_id, true ) ) { | |
| 2001 | - $author_id = $requested_author_id; | |
| 2002 | - } | |
| 2003 | - } | |
| 2004 | - | |
| 2005 | - $attached = (int) $wpdb->get_var( | |
| 1972 | + // Override post author id. | |
| 1973 | + $author_id = isset( $_POST['post_author_override'] ) ? $_POST['post_author_override'] : $post->post_author; //phpcs:ignore | |
| 1974 | + $attached = (int) $wpdb->get_var( | |
| 2006 | 1975 | $wpdb->prepare( |
| 2007 | 1976 | "SELECT COUNT(umeta_id) FROM {$wpdb->usermeta} |
| 2008 | 1977 | WHERE user_id = %d |
| 2009 | 1978 | AND meta_key = '_tutor_instructor_course_id' |
| @@ -2028,20 +1997,8 @@ | ||
| 2028 | 1997 | update_post_meta( $post_ID, $key, ( isset( $_POST[ $key ] ) ? 'yes' : 'no' ) ); |
| 2029 | 1998 | } |
| 2030 | 1999 | } |
| 2031 | 2000 | |
| 2032 | - /** | |
| 2033 | - * Update course content if main author is changed and multi-instructor addon is disabled. | |
| 2034 | - * | |
| 2035 | - * @since 4.0.4 | |
| 2036 | - */ | |
| 2037 | - if ( ! $attached && ! tutor_utils()->is_addon_enabled( 'tutor-multi-instructors' ) ) { | |
| 2038 | - CourseModel::update_course_content_author( $post_ID, (int) $author_id ); | |
| 2039 | - // Remove all existing instructors from the course and add the new one. | |
| 2040 | - delete_metadata( 'user', 0, '_tutor_instructor_course_id', $post_ID, true ); | |
| 2041 | - add_user_meta( $author_id, '_tutor_instructor_course_id', $post_ID ); | |
| 2042 | - } | |
| 2043 | - | |
| 2044 | 2001 | do_action( 'tutor_save_course_after', $post_ID, $post ); |
| 2045 | 2002 | } |
| 2046 | 2003 | |
| 2047 | 2004 | /** |
| @@ -2254,9 +2211,9 @@ | ||
| 2254 | 2211 | tutor_utils()->redirect_to( $permalink, __( 'You do not have permission to complete this course.', 'tutor' ), 'error' ); |
| 2255 | 2212 | } else { |
| 2256 | 2213 | CourseModel::mark_course_as_completed( $course_id, $user_id ); |
| 2257 | 2214 | // Set temporary identifier to show review pop up. |
| 2258 | - self::set_review_popup_data( $user_id, $course_id ); | |
| 2215 | + self::set_review_popup_data( $user_id, $course_id, $permalink ); | |
| 2259 | 2216 | |
| 2260 | 2217 | wp_safe_redirect( $permalink ); |
| 2261 | 2218 | exit; |
| 2262 | 2219 | } |
| @@ -2658,9 +2615,9 @@ | ||
| 2658 | 2615 | * |
| 2659 | 2616 | * @return string |
| 2660 | 2617 | */ |
| 2661 | 2618 | public function enable_disable_material_includes( $html ) { |
| 2662 | - $disable_option = ! (bool) get_tutor_option( 'enable_course_material', true ); | |
| 2619 | + $disable_option = ! (bool) get_tutor_option( 'enable_course_material', true, true ); | |
| 2663 | 2620 | if ( $disable_option ) { |
| 2664 | 2621 | return ''; |
| 2665 | 2622 | } |
| 2666 | 2623 | return $html; |
| @@ -2794,11 +2751,11 @@ | ||
| 2794 | 2751 | $hide_course_from_shop_page = (bool) get_tutor_option( 'hide_course_from_shop_page' ); |
| 2795 | 2752 | if ( ! $hide_course_from_shop_page ) { |
| 2796 | 2753 | return; |
| 2797 | 2754 | } |
| 2798 | - add_filter( 'woocommerce_product_query', array( $this, 'filter_woocommerce_product_query' ) ); | |
| 2799 | - add_filter( 'edd_downloads_query', array( $this, 'filter_edd_downloads_query' ), 10 ); | |
| 2800 | - add_filter( 'pre_get_posts', array( $this, 'filter_archive_meta_query' ), 1 ); | |
| 2755 | + add_action( 'woocommerce_product_query', array( $this, 'filter_woocommerce_product_query' ) ); | |
| 2756 | + add_filter( 'edd_downloads_query', array( $this, 'filter_edd_downloads_query' ), 10, 2 ); | |
| 2757 | + add_action( 'pre_get_posts', array( $this, 'filter_archive_meta_query' ), 1 ); | |
| 2801 | 2758 | } |
| 2802 | 2759 | |
| 2803 | 2760 | |
| 2804 | 2761 | /** |
| @@ -2930,9 +2887,9 @@ | ||
| 2930 | 2887 | return null; |
| 2931 | 2888 | } |
| 2932 | 2889 | |
| 2933 | 2890 | $completed_lessons = tutor_utils()->get_completed_lesson_count_by_course( $course_id, $user_id ); |
| 2934 | - $total_lessons = tutor_utils()->get_lesson_count_by_course( $course_id ); // @phpstan-ignore method.notFound | |
| 2891 | + $total_lessons = tutor_utils()->get_lesson_count_by_course( $course_id ); | |
| 2935 | 2892 | |
| 2936 | 2893 | if ( $completed_lessons < $total_lessons ) { |
| 2937 | 2894 | return __( 'Complete all lessons to mark this course as complete', 'tutor' ); |
| 2938 | 2895 | } |
| @@ -3150,9 +3107,9 @@ | ||
| 3150 | 3107 | * @since 1.9.8 |
| 3151 | 3108 | * |
| 3152 | 3109 | * @param integer $course_id course ID. |
| 3153 | 3110 | * @param integer $user_id user ID. |
| 3154 | - * | |
| 3111 | + * | |
| 3155 | 3112 | * @return void |
| 3156 | 3113 | */ |
| 3157 | 3114 | public function enroll_after_login_if_attempt( int $course_id, int $user_id ) { |
| 3158 | 3115 | $course_id = sanitize_text_field( $course_id ); |