Addons.php
4 years ago
Admin.php
4 years ago
Ajax.php
4 years ago
Announcements.php
4 years ago
Assets.php
4 years ago
Backend_Page_Trait.php
4 years ago
Course.php
4 years ago
Course_Filter.php
4 years ago
Course_List.php
4 years ago
Course_Settings_Tabs.php
4 years ago
Course_Widget.php
4 years ago
Custom_Validation.php
5 years ago
Dashboard.php
4 years ago
FormHandler.php
4 years ago
Frontend.php
4 years ago
Gutenberg.php
4 years ago
Input.php
4 years ago
Instructor.php
4 years ago
Instructors_List.php
4 years ago
Lesson.php
4 years ago
Options_V2.php
4 years ago
Post_types.php
4 years ago
Private_Course_Access.php
4 years ago
Q_and_A.php
4 years ago
Question_Answers_List.php
4 years ago
Quiz.php
4 years ago
Quiz_Attempts_List.php
4 years ago
RestAPI.php
4 years ago
Reviews.php
4 years ago
Rewrite_Rules.php
4 years ago
Shortcode.php
4 years ago
Student.php
4 years ago
Students_List.php
4 years ago
Taxonomies.php
4 years ago
Template.php
4 years ago
Theme_Compatibility.php
5 years ago
Tools.php
4 years ago
Tools_V2.php
4 years ago
Tutor.php
4 years ago
TutorEDD.php
4 years ago
Tutor_Base.php
5 years ago
Tutor_List_Table.php
4 years ago
Tutor_Setup.php
4 years ago
Upgrader.php
4 years ago
User.php
4 years ago
Utils.php
4 years ago
Video_Stream.php
4 years ago
Withdraw.php
4 years ago
Withdraw_Requests_List.php
4 years ago
WooCommerce.php
4 years ago
Dashboard.php
104 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Dashboard class |
| 4 | * |
| 5 | * @author: themeum |
| 6 | * @author_uri: https://themeum.com |
| 7 | * @package Tutor |
| 8 | * @since v.1.3.4 |
| 9 | */ |
| 10 | |
| 11 | namespace TUTOR; |
| 12 | |
| 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | exit; |
| 15 | } |
| 16 | |
| 17 | class Dashboard { |
| 18 | |
| 19 | public function __construct() { |
| 20 | add_action( 'template_redirect', array($this, 'create_draft') ); |
| 21 | add_action('tutor_load_template_before', array($this, 'tutor_load_template_before'), 10, 2); |
| 22 | add_action('tutor_load_template_after', array($this, 'tutor_load_template_after'), 10, 2); |
| 23 | add_filter('should_tutor_load_template', array($this, 'should_tutor_load_template'), 10, 2); |
| 24 | } |
| 25 | |
| 26 | public function create_draft() { |
| 27 | |
| 28 | if(is_admin()) { |
| 29 | return; |
| 30 | } |
| 31 | |
| 32 | global $wp_query; |
| 33 | |
| 34 | $tutor_dashboard_page = tutor_utils()->array_get( 'query_vars.tutor_dashboard_page', $wp_query ); |
| 35 | |
| 36 | if ( $tutor_dashboard_page === 'create-course' && tutor_utils()->is_instructor(get_current_user_id(), true)) { |
| 37 | |
| 38 | /** |
| 39 | * Get course which currently in edit, or insert new course |
| 40 | */ |
| 41 | $course_ID = (int) tutor_utils()->array_get( 'course_ID', $_GET ); |
| 42 | |
| 43 | if ( !$course_ID ) { |
| 44 | $post_type = tutor()->course_post_type; |
| 45 | $course_id = wp_insert_post( |
| 46 | array( |
| 47 | 'post_title' => __( 'Auto Draft', 'tutor' ), |
| 48 | 'post_type' => $post_type, |
| 49 | 'post_status' => 'draft', |
| 50 | ) |
| 51 | ); |
| 52 | |
| 53 | $red_url = add_query_arg( array('course_ID' => $course_id ), tutor_utils()->tutor_dashboard_url('create-course') ); |
| 54 | wp_redirect( $red_url ); |
| 55 | exit; |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @param $template |
| 62 | * @param $variables |
| 63 | */ |
| 64 | public function tutor_load_template_before( $template, $variables ) { |
| 65 | global $wp_query; |
| 66 | |
| 67 | $tutor_dashboard_page = tutor_utils()->array_get( 'query_vars.tutor_dashboard_page', $wp_query ); |
| 68 | if ( $tutor_dashboard_page === 'create-course' && tutor_utils()->is_instructor(get_current_user_id(), true)) { |
| 69 | global $post; |
| 70 | wp_reset_query(); |
| 71 | |
| 72 | /** |
| 73 | * Get course which currently in edit, or insert new course |
| 74 | */ |
| 75 | $course_ID = (int) tutor_utils()->array_get( 'course_ID', $_GET ); |
| 76 | |
| 77 | if ( $course_ID ) { |
| 78 | $post_id = $course_ID; |
| 79 | } else { |
| 80 | exit(__('Course ID not found. Try reloading.', 'tutor')); |
| 81 | } |
| 82 | |
| 83 | $post = get_post( $post_id ); |
| 84 | setup_postdata( $post ); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | public function tutor_load_template_after() { |
| 89 | global $wp_query; |
| 90 | |
| 91 | $tutor_dashboard_page = tutor_utils()->array_get( 'query_vars.tutor_dashboard_page', $wp_query ); |
| 92 | if ( $tutor_dashboard_page === 'create-course' ) { |
| 93 | wp_reset_query(); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | public function should_tutor_load_template( $bool, $template ) { |
| 98 | if ( $template === 'dashboard.create-course' && ! tutor()->has_pro ) { |
| 99 | return false; |
| 100 | } |
| 101 | return $bool; |
| 102 | } |
| 103 | } |
| 104 |