| 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 |
class Dashboard { |
| 17 |
|
| 18 |
public function __construct() { |
| 19 |
add_action('tutor_load_template_before', array($this, 'tutor_load_template_before'), 10, 2); |
| 20 |
add_action('tutor_load_template_after', array($this, 'tutor_load_template_after'), 10, 2); |
| 21 |
add_filter('should_tutor_load_template', array($this, 'should_tutor_load_template'), 10, 2); |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* @param $template |
| 26 |
* @param $variables |
| 27 |
*/ |
| 28 |
public function tutor_load_template_before($template, $variables){ |
| 29 |
global $wp_query; |
| 30 |
|
| 31 |
$tutor_dashboard_page = tutor_utils()->array_get('query_vars.tutor_dashboard_page', $wp_query); |
| 32 |
if ($tutor_dashboard_page === 'create-course') { |
| 33 |
global $post; |
| 34 |
wp_reset_query(); |
| 35 |
|
| 36 |
|
| 37 |
/** |
| 38 |
* Get course which currently in edit, or insert new course |
| 39 |
*/ |
| 40 |
$course_ID = (int) sanitize_text_field(tutor_utils()->array_get('course_ID', $_GET)); |
| 41 |
|
| 42 |
if ($course_ID){ |
| 43 |
$post_id = $course_ID; |
| 44 |
}else{ |
| 45 |
$post_type = tutor()->course_post_type; |
| 46 |
$post_id = wp_insert_post( array( 'post_title' => __( 'Auto Draft', 'tutor' ), 'post_type' => $post_type, 'post_status' => 'auto-draft' ) ); |
| 47 |
} |
| 48 |
|
| 49 |
$post = get_post( $post_id ); |
| 50 |
setup_postdata( $post ); |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
public function tutor_load_template_after(){ |
| 55 |
global $wp_query; |
| 56 |
|
| 57 |
$tutor_dashboard_page = tutor_utils()->array_get('query_vars.tutor_dashboard_page', $wp_query); |
| 58 |
if ($tutor_dashboard_page === 'create-course'){ |
| 59 |
wp_reset_query(); |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
public function should_tutor_load_template($bool, $template){ |
| 64 |
if ($template === 'dashboard.create-course' && ! tutor()->has_pro){ |
| 65 |
return false; |
| 66 |
} |
| 67 |
return $bool; |
| 68 |
} |
| 69 |
|
| 70 |
} |