Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/tutor-pro/classes/Dashboard.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
/**
3
+
* Dashboard Class
4
+
*
5
+
* @package TutorPro\Classes
6
+
* @author Themeum <support@themeum.com>
7
+
* @link https://themeum.com
8
+
* @since 2.1.0
9
+
*/
10
+
11
+
namespace TUTOR_PRO;
12
+
13
+
if ( ! defined( 'ABSPATH' ) ) {
14
+
exit;
15
+
}
16
+
17
+
use TUTOR\Input;
18
+
use Tutor\Models\CourseModel;
19
+
20
+
/**
21
+
* Dashboard Class
22
+
* Used for handle frontend dashboard for PRO user
23
+
*
24
+
* @since 2.1.0
25
+
*/
26
+
class Dashboard {
27
+
/**
28
+
* Constructor
29
+
*
30
+
* @param boolean $register_hooks pass false value to reuse.
31
+
*/
32
+
public function __construct( $register_hooks = true ) {
33
+
if ( $register_hooks ) {
34
+
add_action( 'wp_loaded', array( $this, 'handle_course_status' ) );
35
+
}
36
+
37
+
}
38
+
39
+
/**
40
+
* Handler for change course status
41
+
*
42
+
* @since 2.1.0
43
+
*
44
+
* @return void
45
+
*/
46
+
public function handle_course_status() {
47
+
$action = Input::get( 'tutor_action' );
48
+
$id = Input::get( 'course_id', 0, Input::TYPE_INT );
49
+
$status = Input::get( 'status' );
50
+
51
+
if ( 'update_course_status' !== $action
52
+
|| 0 === $id
53
+
|| ! in_array( $status, array( CourseModel::STATUS_DRAFT, CourseModel::STATUS_PENDING ), true )
54
+
|| ! get_post( $id )
55
+
) {
56
+
// Invalid request for status update.
57
+
return;
58
+
}
59
+
60
+
tutor_utils()->checking_nonce( 'GET' );
61
+
62
+
if ( ! tutor_utils()->can_user_manage( 'course', $id ) ) {
63
+
return;
64
+
}
65
+
66
+
$can_publish_course = current_user_can( 'administrator' ) || (bool) tutor_utils()->get_option( 'instructor_can_publish_course' );
67
+
68
+
if ( true === $can_publish_course && CourseModel::STATUS_PENDING === $status ) {
69
+
$status = CourseModel::STATUS_PUBLISH;
70
+
}
71
+
72
+
$args = array(
73
+
'ID' => $id,
74
+
'post_status' => $status,
75
+
);
76
+
77
+
wp_update_post( $args );
78
+
79
+
$link = wp_get_referer();
80
+
$flash_message = null;
81
+
82
+
if ( CourseModel::STATUS_PUBLISH === $status ) {
83
+
$flash_message = __( 'Course successfully published', 'tutor-pro' );
84
+
$link = tutor_utils()->tutor_dashboard_url( 'my-courses' );
85
+
}
86
+
87
+
if ( CourseModel::STATUS_PENDING === $status ) {
88
+
$flash_message = __( 'Course submitted for review', 'tutor-pro' );
89
+
$link = tutor_utils()->tutor_dashboard_url( 'my-courses/pending-courses' );
90
+
}
91
+
92
+
if ( CourseModel::STATUS_DRAFT === $status ) {
93
+
$flash_message = __( 'Course moved to draft', 'tutor-pro' );
94
+
$link = tutor_utils()->tutor_dashboard_url( 'my-courses/draft-courses' );
95
+
}
96
+
97
+
tutor_utils()->redirect_to( $link, $flash_message );
98
+
}
99
+
}
100
+