PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 3.9.9
Tutor LMS – eLearning and online course solution v3.9.9
3.9.14 3.9.13 3.9.12 3.9.11 trunk 1.0.0 1.0.0-alpha 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.2.0 1.2.1 1.2.11 1.2.12 1.2.13 1.2.20 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.1 1.8.10 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.14 1.9.15 1.9.16 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.10 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.10 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.3.0 2.4.0 2.5.0 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.1.0 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / classes / Admin.php
tutor / classes Last commit date
Addons.php 11 months ago Admin.php 2 months ago Ajax.php 9 months ago Announcements.php 1 year ago Assets.php 7 months ago Backend_Page_Trait.php 1 year ago BaseController.php 1 year ago Config.php 11 months ago Container.php 11 months ago Course.php 2 months ago Course_Embed.php 3 years ago Course_Filter.php 1 year ago Course_List.php 5 months ago Course_Settings_Tabs.php 1 year ago Course_Widget.php 1 year ago Custom_Validation.php 3 years ago Dashboard.php 1 year ago Earnings.php 9 months ago FormHandler.php 2 years ago Frontend.php 1 year ago Gutenberg.php 1 year ago Icon.php 8 months ago Input.php 1 year ago Instructor.php 2 months ago Instructors_List.php 2 months ago Lesson.php 8 months ago Options_V2.php 7 months ago Permalink.php 2 years ago Post_types.php 1 year ago Private_Course_Access.php 1 year ago Q_And_A.php 10 months ago Question_Answers_List.php 11 months ago Quiz.php 5 months ago QuizBuilder.php 3 months ago Quiz_Attempts_List.php 9 months ago RestAPI.php 2 years ago Reviews.php 9 months ago Rewrite_Rules.php 2 years ago Shortcode.php 9 months ago Singleton.php 1 year ago Student.php 2 months ago Students_List.php 1 year ago Taxonomies.php 1 year ago Template.php 9 months ago Theme_Compatibility.php 3 years ago Tools.php 1 year ago Tools_V2.php 1 year ago Tutor.php 3 months ago TutorEDD.php 1 year ago Tutor_Base.php 2 years ago Tutor_Setup.php 8 months ago Upgrader.php 9 months ago User.php 4 months ago Utils.php 5 months ago Video_Stream.php 3 years ago WhatsNew.php 9 months ago Withdraw.php 1 year ago Withdraw_Requests_List.php 11 months ago WooCommerce.php 7 months ago
Admin.php
913 lines
1 <?php
2 /**
3 * Manage admin menu and plugin related logic
4 *
5 * @package Tutor
6 * @author Themeum <support@themeum.com>
7 * @link https://themeum.com
8 * @since 1.0.0
9 */
10
11 namespace TUTOR;
12
13 use Tutor\Ecommerce\OrderController;
14 use Tutor\Helpers\HttpHelper;
15 use TUTOR\Input;
16 use Tutor\Models\CourseModel;
17 use Tutor\Traits\JsonResponse;
18
19 if ( ! defined( 'ABSPATH' ) ) {
20 exit;
21 }
22
23 /**
24 * Admin Class
25 *
26 * @since 1.0.0
27 */
28 class Admin {
29 use JsonResponse;
30
31 /**
32 * Constructor
33 *
34 * @since 1.0.0
35 * @return void
36 */
37 public function __construct() {
38
39 add_action( 'admin_notices', array( $this, 'show_unstable_version_admin_notice' ) );
40 add_action( 'admin_notices', array( $this, 'show_v4_beta_notice' ) );
41
42 add_action( 'admin_menu', array( $this, 'register_menu' ) );
43 // Force activate menu for necessary.
44 add_filter( 'parent_file', array( $this, 'parent_menu_active' ) );
45 add_filter( 'submenu_file', array( $this, 'submenu_file_active' ), 10, 2 );
46
47 add_action( 'admin_init', array( $this, 'filter_posts_for_instructors' ) );
48 add_action( 'load-post.php', array( $this, 'check_if_current_users_post' ) );
49
50 add_filter( 'plugin_action_links_' . plugin_basename( TUTOR_FILE ), array( $this, 'plugin_action_links' ) );
51
52 // Plugin Row Meta.
53 add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 );
54
55 // Admin Footer Text.
56 add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ), 1 );
57 // Register Course Widget.
58 add_action( 'widgets_init', array( $this, 'register_course_widget' ) );
59
60 // Handle flash toast message for redirect_to util helper.
61 add_action( 'admin_head', array( new Utils(), 'handle_flash_message' ), 999 );
62
63 add_action( 'admin_bar_menu', array( $this, 'add_toolbar_items' ), 100 );
64
65 add_action( 'wp_ajax_tutor_do_not_show_feature_page', array( $this, 'handle_do_not_show_feature_page' ) );
66 }
67
68 /**
69 * Show unstable version notice.
70 *
71 * @since 3.0.0
72 *
73 * @return void
74 */
75 public function show_unstable_version_admin_notice() {
76 $version = tutor_utils()->extract_version_details( TUTOR_VERSION );
77 if ( ! $version->is_stable ) {
78 /* translators: %s: version name */
79 $message = sprintf( __( 'You\'re currently using Tutor LMS %s. To ensure stability, please do not use it on a live site.', 'tutor' ), '<strong>' . $version->version . '</strong>' );
80 ?>
81 <div class="notice notice-warning">
82 <p><strong><?php esc_html_e( 'Warning!', 'tutor' ); ?></strong></p>
83 <p><?php echo wp_kses_post( $message ); ?></p>
84 </div>
85 <?php
86 }
87 }
88
89 /**
90 * Show version 4 admin notice.
91 *
92 * @since 3.9.9
93 *
94 * @return void
95 */
96 public function show_v4_beta_notice() {
97 if ( version_compare( TUTOR_VERSION, '4', '<' ) ) {
98 ?>
99 <div class="tutor-v4-beta-notice notice is-dismissible">
100 <div class="tutor-v4-beta-notice-left">
101 <img src="<?php echo esc_url( tutor()->url . 'assets/images/v4-notice-logo.svg' ); ?>" alt="Tutor LMS 4.0 Beta">
102 </div>
103 <div class="tutor-v4-beta-notice-right">
104 <div class="tutor-v4-beta-notice-right-content">
105 <h3><?php esc_html_e( 'Be the First to Try Tutor LMS 4.0 Beta!', 'tutor' ); ?></h3>
106 <p>
107 <?php
108 echo wp_kses(
109 sprintf(
110 /* translators: 1: opening anchor tag, 2: closing anchor tag */
111 __(
112 'Explore the upcoming features of Tutor LMS 4.0, test the experience, and help us improve with your valuable %1$sfeedback%2$s.',
113 'tutor'
114 ),
115 '<a href="https://forms.gle/Dxc1CWT63UcEAJGR9" target="_blank" rel="noopener noreferrer">',
116 ' <i class="tutor-icon-external-link" aria-hidden="true"></i></a>'
117 ),
118 array(
119 'a' => array(
120 'href' => true,
121 'target' => true,
122 'rel' => true,
123 ),
124 'i' => array(
125 'class' => true,
126 'aria-hidden' => true,
127 ),
128 )
129 );
130 ?>
131 </p>
132 </div>
133 <div class="tutor-v4-beta-notice-right-buttons">
134 <a href="https://tutorlms.com/blog/first-look-into-tutor-lms-4-0/?nocache=1" target="_blank" rel="noopener noreferrer" class="tutor-btn tutor-btn-tertiary tutor-gap-4px tutor-text-nowrap">
135 <?php esc_html_e( 'Try now', 'tutor' ); ?>
136 </a>
137 </div>
138 </div>
139 </div>
140 <?php
141 }
142 }
143
144 /**
145 * Register admin menus
146 *
147 * @since 1.0.0
148 * @since 3.8.0 re-organize admin menu.
149 *
150 * @return void
151 */
152 public function register_menu() {
153 $has_pro = tutor()->has_pro;
154
155 $unanswered_questions = tutor_utils()->unanswered_question_count();
156 $unanswered_bubble = '';
157 if ( $unanswered_questions ) {
158 $unanswered_bubble = '<span class="update-plugins count-' . $unanswered_questions . '"><span class="plugin-count">' . $unanswered_questions . '</span></span>';
159 }
160
161 $course_post_type = tutor()->course_post_type;
162
163 $pro_text = '';
164 if ( $has_pro ) {
165 $pro_text = ' ' . apply_filters( 'tutor_pro_flag', __( 'Pro', 'tutor' ) );
166 }
167
168 $enable_course_marketplace = (bool) tutor_utils()->get_option( 'enable_course_marketplace' );
169
170 $welcome = Tutor_Setup::is_welcome_page_visited();
171
172 $root_page = array( $this, 'tutor_course_list' );
173 if ( false === $welcome && Input::has( 'page' ) && 'tutor' === Input::get( 'page' ) && Input::has( 'welcome' ) ) {
174 $root_page = array( $this, 'welcome_page' );
175 }
176
177 $icon_base64_uri = 'data:image/svg+xml;base64,' . base64_encode( '<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1000 1139"><defs/><path fill-rule="evenodd" clip-rule="evenodd" d="M341.652 622.4c-23.412 0-43.222-19.8-43.222-43.2v-99c0-23.4 19.81-43.2 43.222-43.2 23.412 0 43.222 19.8 43.222 43.2v99c0 23.4-18.009 43.2-43.222 43.2 1.801 0 1.801 0 0 0zM655.01 622.4c-23.412 0-43.222-18-43.222-43.2v-99c0-23.4 19.81-43.2 43.222-43.2 23.412 0 43.222 19.8 43.222 43.2v99c0 25.2-19.81 43.2-43.222 43.2z" fill="#9DA2A8"/><path fill-rule="evenodd" clip-rule="evenodd" d="M255.204 406.4c18.009-37.8 54.028-63 95.449-63 61.231 1.8 108.055 52.2 106.254 113.4v203.4c3.602 21.6 23.412 37.8 45.023 34.2 18.009-1.8 32.416-16.2 34.217-34.2V455c-1.801-61.2 46.824-111.6 106.254-113.4 39.621 0 75.639 21.6 93.648 59.4 68.435 133.2 14.407 295.2-117.06 363.6C487.523 833 325.44 779 258.806 647.6c-39.62-75.6-39.62-165.6-3.602-241.2zM426.291 140h151.277v59.4c-25.212-5.4-52.226-9-77.439-9-25.213 0-50.426 3.6-75.639 7.2l1.801-57.6zm414.211 388.8c0-122.4-66.634-235.8-172.888-295.2V140h64.833c25.213 0 45.023-19.8 45.023-45s-21.611-45-45.023-45H271.413C246.2 51.8 226.39 71.6 226.39 96.8c0 25.2 19.81 45 45.023 45h66.633v91.8c-163.883 90-230.517 298.8-135.068 459 3.602 5.4-3.602-5.4 0 0C338.046 930.2 687.424 948.2 802.683 950c10.805 0 19.81-3.6 27.014-10.8 7.203-7.2 10.805-18 10.805-27V528.8z" fill="#9DA2A8"/></svg>' );
178 $menu_position = 2;
179
180 add_menu_page(
181 __( 'Tutor LMS', 'tutor' ) . $pro_text,
182 __( 'Tutor LMS', 'tutor' ) . $pro_text,
183 'manage_tutor_instructor',
184 'tutor',
185 $root_page,
186 $icon_base64_uri,
187 $menu_position
188 );
189
190 new WhatsNew();
191
192 $admin_menu = apply_filters(
193 'tutor_admin_menu',
194 array(
195 'group_one' => array(
196 'courses' => array(
197 'parent_slug' => 'tutor',
198 'page_title' => __( 'Courses', 'tutor' ),
199 'menu_title' => __( 'Courses', 'tutor' ),
200 'capability' => 'manage_tutor_instructor',
201 'menu_slug' => 'tutor',
202 'callback' => array( $this, 'tutor_course_list' ),
203 ),
204 'content_bank' => null,
205 'course_builder' => array(
206 'parent_slug' => 'tutor',
207 'page_title' => __( 'Course Builder', 'tutor' ),
208 'menu_title' => '<span class="tutor-create-course">Create Course</span>',
209 'capability' => 'manage_tutor_instructor',
210 'menu_slug' => 'create-course',
211 'callback' => array( new Course( false ), 'load_course_builder' ),
212 ),
213 'categories' => array(
214 'parent_slug' => 'tutor',
215 'page_title' => __( 'Categories', 'tutor' ),
216 'menu_title' => __( 'Categories', 'tutor' ),
217 'capability' => 'manage_tutor',
218 'menu_slug' => 'edit-tags.php?taxonomy=course-category&post_type=' . $course_post_type,
219 ),
220 'tags' => array(
221 'parent_slug' => 'tutor',
222 'page_title' => __( 'Tags', 'tutor' ),
223 'menu_title' => __( 'Tags', 'tutor' ),
224 'capability' => 'manage_tutor',
225 'menu_slug' => 'edit-tags.php?taxonomy=course-tag&post_type=' . $course_post_type,
226 ),
227 ),
228 'group_two' => array(
229 'orders' => null,
230 'subscriptions' => null,
231 'coupons' => null,
232 'students' => array(
233 'parent_slug' => 'tutor',
234 'page_title' => __( 'Students', 'tutor' ),
235 'menu_title' => __( 'Students', 'tutor' ),
236 'capability' => 'manage_tutor',
237 'menu_slug' => Students_List::STUDENTS_LIST_PAGE,
238 'callback' => array( $this, 'tutor_students' ),
239
240 ),
241 'announcements' => array(
242 'parent_slug' => 'tutor',
243 'page_title' => __( 'Announcements', 'tutor' ),
244 'menu_title' => __( 'Announcements', 'tutor' ),
245 'capability' => 'manage_tutor_instructor',
246 'menu_slug' => 'tutor_announcements',
247 'callback' => array( $this, 'tutor_announcements' ),
248
249 ),
250 'assignments' => null,
251 'quiz_attempts' => array(
252 'parent_slug' => 'tutor',
253 'page_title' => __( 'Quiz Attempts', 'tutor' ),
254 'menu_title' => __( 'Quiz Attempts', 'tutor' ),
255 'capability' => 'manage_tutor_instructor',
256 'menu_slug' => Quiz_Attempts_List::QUIZ_ATTEMPT_PAGE,
257 'callback' => array( $this, 'quiz_attempts' ),
258 ),
259 'q_and_a' => array(
260 'parent_slug' => 'tutor',
261 'page_title' => __( 'Q&A', 'tutor' ),
262 'menu_title' => __( 'Q&A ', 'tutor' ) . $unanswered_bubble,
263 'capability' => 'manage_tutor_instructor',
264 'menu_slug' => Question_Answers_List::QUESTION_ANSWER_PAGE,
265 'callback' => array( $this, 'question_answer' ),
266 ),
267 'enrollments' => null,
268 'reports' => null,
269 'gradebook' => null,
270 'instructors' => $enable_course_marketplace ? array(
271 'parent_slug' => 'tutor',
272 'page_title' => __( 'Instructors', 'tutor' ),
273 'menu_title' => __( 'Instructors', 'tutor' ),
274 'capability' => 'manage_tutor',
275 'menu_slug' => Instructors_List::INSTRUCTOR_LIST_PAGE,
276 'callback' => array( $this, 'tutor_instructors' ),
277 ) : null,
278 'withdraw_requests' => $enable_course_marketplace ? array(
279 'parent_slug' => 'tutor',
280 'page_title' => __( 'Withdraw Requests', 'tutor' ),
281 'menu_title' => __( 'Withdraw Requests', 'tutor' ),
282 'capability' => 'manage_tutor',
283 'menu_slug' => Withdraw_Requests_List::WITHDRAW_REQUEST_LIST_PAGE,
284 'callback' => array( $this, 'withdraw_requests' ),
285 ) : null,
286 ),
287 'group_three' => array(
288 'google_classroom' => null,
289 'zoom' => null,
290 'google_meet' => null,
291 'h5p' => null,
292 'themes' => array(
293 'parent_slug' => 'tutor',
294 'page_title' => __( 'Themes', 'tutor' ),
295 'menu_title' => __( 'Themes', 'tutor' ),
296 'capability' => 'manage_tutor',
297 'menu_slug' => 'tutor-themes',
298 'callback' => array( $this, 'tutor_themes' ),
299 ),
300 'addons' => array(
301 'parent_slug' => 'tutor',
302 'page_title' => __( 'Addons', 'tutor' ),
303 'menu_title' => __( 'Addons', 'tutor' ),
304 'capability' => 'manage_tutor',
305 'menu_slug' => 'tutor-addons',
306 'callback' => array( $this, 'enable_disable_addons' ),
307 ),
308 'tools' => array(
309 'parent_slug' => 'tutor',
310 'page_title' => __( 'Tools', 'tutor' ),
311 'menu_title' => __( 'Tools', 'tutor' ),
312 'capability' => 'manage_tutor',
313 'menu_slug' => 'tutor-tools',
314 'callback' => array( new Tools_V2(), 'load_tools_page' ),
315 ),
316 'settings' => array(
317 'parent_slug' => 'tutor',
318 'page_title' => __( 'Settings', 'tutor' ),
319 'menu_title' => __( 'Settings', 'tutor' ),
320 'capability' => 'manage_tutor',
321 'menu_slug' => 'tutor_settings',
322 'callback' => array( new Options_V2(), 'load_settings_page' ),
323 ),
324 'license' => null,
325 'whats_new' => null,
326 'upgrade_to_pro' => $has_pro ? null : array(
327 'parent_slug' => 'tutor',
328 'page_title' => __( 'Upgrade to Pro', 'tutor' ),
329 'menu_title' => sprintf( '<span class="tutor-get-pro-text">%s</span>', __( 'Upgrade to Pro', 'tutor' ) ),
330 'capability' => 'manage_options',
331 'menu_slug' => 'tutor-get-pro',
332 'callback' => array( $this, 'tutor_get_pro' ),
333 ),
334 ),
335 )
336 );
337
338 foreach ( $admin_menu as $group => $menu ) {
339 foreach ( $menu as $name => $args ) {
340 if ( empty( $args ) ) {
341 continue;
342 }
343
344 // Backward compatibility hook.
345 if ( 'addons' === $name ) {
346 do_action( 'tutor_admin_register' );
347 }
348
349 // Backward compatibility hook.
350 do_action( "tutor_before_{$name}_admin_menu" );
351
352 do_action( "tutor_before_{$name}_menu" );
353 add_submenu_page( $args['parent_slug'], $args['page_title'], $args['menu_title'], $args['capability'], $args['menu_slug'], $args['callback'] ?? '', $args['position'] ?? null );
354
355 // Backward compatibility hook.
356 do_action( "tutor_after_{$name}_menu" );
357
358 do_action( "tutor_after_{$name}_admin_menu" );
359 }
360
361 if ( 'group_three' !== $group ) {
362 if ( 'group_two' === $group && ! current_user_can( 'manage_options' ) ) {
363 continue;
364 }
365
366 add_submenu_page( 'tutor', '', '<span class="tutor-admin-menu-separator"></span>', 'manage_tutor_instructor', '#' );
367 }
368 }
369 }
370
371 /**
372 * Tutor template view
373 *
374 * @since 3.6.0
375 */
376 public function tutor_themes() {
377 include tutor()->path . 'views/template-import/templates.php';
378 }
379
380 /**
381 * Welcome page opt-out
382 *
383 * @since 3.0.0
384 */
385 public function handle_do_not_show_feature_page() {
386 tutor_utils()->check_nonce();
387
388 if ( ! User::is_admin() ) {
389 $this->json_response(
390 tutor_utils()->error_message(),
391 null,
392 HttpHelper::STATUS_BAD_REQUEST
393 );
394 }
395
396 update_option( 'tutor-new-feature', '3.0.0' );
397 $this->json_response( __( 'Success', 'tutor' ) );
398 }
399
400 /**
401 * Show Feature Promotion Page for Free User.
402 *
403 * @since 2.2.0
404 *
405 * @return void
406 */
407 public function feature_promotion_page() {
408 include tutor()->path . 'views/pages/welcome.php';
409 // include tutor()->path . 'views/pages/feature-promotion.php';
410 }
411
412 /**
413 * Show students page
414 *
415 * @since 1.0.0
416 * @return void
417 */
418 public function tutor_students() {
419 include tutor()->path . 'views/pages/students.php';
420 }
421
422 /**
423 * Show instructor page
424 *
425 * @since 1.0.0
426 * @return void
427 */
428 public function tutor_instructors() {
429 include tutor()->path . 'views/pages/instructors.php';
430 }
431
432 /**
433 * Show announcements page
434 *
435 * @since 1.0.0
436 * @return void
437 */
438 public function tutor_announcements() {
439 include tutor()->path . 'views/pages/announcements.php';
440 }
441
442 /**
443 * Show Q&A page
444 *
445 * @since 1.0.0
446 * @return void
447 */
448 public function question_answer() {
449 include tutor()->path . 'views/pages/question_answer.php';
450 }
451
452 /**
453 * Show quiz attempts page
454 *
455 * @since 1.0.0
456 * @return void
457 */
458 public function quiz_attempts() {
459 include tutor()->path . 'views/pages/quiz_attempts.php';
460 }
461
462 /**
463 * Show the withdraw requests table
464 *
465 * @since 1.2.0
466 * @return void
467 */
468 public function withdraw_requests() {
469 include tutor()->path . 'views/pages/withdraw_requests.php';
470 }
471
472 /**
473 * Enable or disable addons
474 *
475 * @since 1.0.0
476 * @return void
477 */
478 public function enable_disable_addons() {
479 include tutor()->path . 'views/pages/enable_disable_addons.php';
480 }
481
482 /**
483 * Tutor tools page (OLD)
484 *
485 * @since 1.0.0
486 * @return void
487 */
488 public function tutor_tools_old() {
489 $tutor_admin_tools_page = Input::get( 'tutor_admin_tools_page' );
490 if ( $tutor_admin_tools_page ) {
491 include apply_filters( 'tutor_admin_tools_page', tutor()->path . "views/pages/{$tutor_admin_tools_page}.php", $tutor_admin_tools_page );
492 } else {
493 $pages = apply_filters(
494 'tutor_tool_pages',
495 array(
496 'tutor_pages' => array( 'title' => __( 'Tutor Pages', 'tutor' ) ),
497 'status' => __( 'Status', 'tutor' ),
498 )
499 );
500
501 $current_page = 'tutor_pages';
502 $requested_page = Input::get( 'sub_page' );
503 if ( $requested_page ) {
504 $current_page = $requested_page;
505 }
506
507 $current_page = str_replace( '/', '', $current_page );
508 $current_page = str_replace( '.', '', $current_page );
509 $current_page = str_replace( '\\', '', $current_page );
510 $current_page = trim( $current_page );
511
512 include tutor()->path . 'views/pages/tools.php';
513 }
514 }
515
516 /**
517 * Show pro upgrade page
518 *
519 * @since 1.0.0
520 * @return void
521 */
522 public function tutor_get_pro() {
523 include tutor()->path . 'views/pages/get-pro.php';
524 }
525
526 /**
527 * Parent menu active
528 *
529 * @since 1.0.0
530 *
531 * @param string $parent_file parent file.
532 * @return string
533 */
534 public function parent_menu_active( $parent_file ) {
535 $taxonomy = Input::get( 'taxonomy' );
536 if ( CourseModel::COURSE_CATEGORY === $taxonomy || CourseModel::COURSE_TAG === $taxonomy ) {
537 return 'tutor';
538 }
539
540 return $parent_file;
541 }
542
543 /**
544 * Sub-menu active
545 *
546 * @since 1.0.0
547 *
548 * @param string $submenu_file submenu file.
549 * @param string $parent_file parent file.
550 *
551 * @return string
552 */
553 public function submenu_file_active( $submenu_file, $parent_file ) {
554 $taxonomy = Input::get( 'taxonomy' );
555 $course_post_type = tutor()->course_post_type;
556
557 if ( CourseModel::COURSE_CATEGORY === $taxonomy ) {
558 return 'edit-tags.php?taxonomy=course-category&post_type=' . $course_post_type;
559 }
560 if ( CourseModel::COURSE_TAG === $taxonomy ) {
561 return 'edit-tags.php?taxonomy=course-tag&post_type=' . $course_post_type;
562 }
563
564 return $submenu_file;
565 }
566
567 /**
568 * Filter posts for instructor
569 *
570 * @since 1.0.0
571 * @return void
572 */
573 public function filter_posts_for_instructors() {
574 if ( ! current_user_can( 'administrator' ) && current_user_can( tutor()->instructor_role ) ) {
575 @remove_menu_page( 'edit-comments.php' ); // Comments.
576 add_filter( 'posts_clauses_request', array( $this, 'posts_clauses_request' ) );
577 }
578 }
579
580 /**
581 * Request for posts clauses
582 *
583 * @since 1.0.0
584 *
585 * @param mixed $clauses clauses.
586 * @return mixed
587 */
588 public function posts_clauses_request( $clauses ) {
589
590 if ( ! is_admin() || ( ! Input::has( 'post_type' ) || Input::get( 'post_type' ) != tutor()->course_post_type ) || tutor_utils()->has_user_role( array( 'administrator', 'editor' ) ) ) {
591 return $clauses;
592 }
593
594 // Need multi instructor check.
595 global $wpdb;
596
597 $user_id = get_current_user_id();
598
599 $get_assigned_courses_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_value from {$wpdb->usermeta} WHERE meta_key = '_tutor_instructor_course_id' AND user_id = %d", $user_id ) );
600 $own_courses = is_array( $get_assigned_courses_ids ) ? $get_assigned_courses_ids : array();
601
602 $in_query_pre = count( $own_courses ) ? implode( ',', $own_courses ) : null;
603 $in_query_where = $in_query_pre ? " OR {$wpdb->posts}.ID IN({$in_query_pre})" : '';
604
605 $course_post_type = tutor()->course_post_type;
606 $custom_author_query = " AND ({$wpdb->posts}.post_type!='{$course_post_type}' OR {$wpdb->posts}.post_author = {$user_id}) {$in_query_where}";
607
608 $clauses['where'] .= $custom_author_query;
609
610 return $clauses;
611 }
612
613 /**
614 * Prevent unauthorised course/lesson edit page by direct URL
615 *
616 * @since 1.0.0
617 * @return void
618 */
619 public function check_if_current_users_post() {
620 if ( current_user_can( 'administrator' ) || ! current_user_can( tutor()->instructor_role ) ) {
621 return;
622 }
623
624 if ( ! empty( Input::get( 'post' ) ) ) {
625 $get_post_id = Input::get( 'post', Input::TYPE_INT );
626 $get_post = get_post( $get_post_id );
627 $tutor_post_types = array( tutor()->course_post_type, tutor()->lesson_post_type );
628
629 $current_user = get_current_user_id();
630
631 if ( in_array( $get_post->post_type, $tutor_post_types ) && $get_post->post_author != $current_user ) {
632 global $wpdb;
633
634 $get_assigned_courses_ids = (int) $wpdb->get_var(
635 $wpdb->prepare(
636 "SELECT user_id
637 from {$wpdb->usermeta}
638 WHERE user_id = %d AND meta_key = '_tutor_instructor_course_id' AND meta_value = %d ",
639 $current_user,
640 $get_post_id
641 )
642 );
643
644 if ( ! $get_assigned_courses_ids ) {
645 wp_die( esc_html__( 'Permission Denied', 'tutor' ) );
646 }
647 }
648 }
649 }
650
651 /**
652 * Scan template files
653 *
654 * @since 1.0.0
655 *
656 * @param string $template_path template file path.
657 * @return array
658 */
659 public static function scan_template_files( $template_path = null ) {
660 if ( ! $template_path ) {
661 $template_path = tutor()->path . 'templates/';
662 }
663
664 $files = @scandir($template_path); // @codingStandardsIgnoreLine.
665 $result = array();
666
667 if ( ! empty( $files ) ) {
668 foreach ( $files as $key => $value ) {
669 if ( ! in_array( $value, array( '.', '..', '.DS_Store' ), true ) ) {
670 if ( is_dir( $template_path . DIRECTORY_SEPARATOR . $value ) ) {
671 $sub_files = self::scan_template_files( $template_path . DIRECTORY_SEPARATOR . $value );
672 foreach ( $sub_files as $sub_file ) {
673 $result[] = $value . DIRECTORY_SEPARATOR . $sub_file;
674 }
675 } else {
676 $result[] = $value;
677 }
678 }
679 }
680 }
681 return $result;
682 }
683
684 /**
685 * Get Template overridden files
686 *
687 * @since 1.0.0
688 * @return array
689 */
690 public static function template_overridden_files() {
691 $template_files = self::scan_template_files();
692
693 $override_files = array();
694 foreach ( $template_files as $file ) {
695 $file_path = null;
696 if ( file_exists( trailingslashit( get_stylesheet_directory() ) . tutor()->template_path . $file ) ) {
697 $file_path = $file;
698 } elseif ( file_exists( trailingslashit( get_template_directory() ) . tutor()->template_path . $file ) ) {
699 $file_path = $file;
700 }
701
702 if ( $file_path ) {
703 $override_files[] = str_replace( WP_CONTENT_DIR . '/themes/', '', $file_path );
704 }
705 }
706
707 return $override_files;
708 }
709
710 /**
711 * Plugin activation link
712 *
713 * @since 1.0.0
714 *
715 * @param array $actions action list.
716 * @return array
717 */
718 public function plugin_action_links( $actions ) {
719 $has_pro = tutor()->has_pro;
720
721 if ( ! $has_pro ) {
722 $actions['tutor_pro_link'] =
723 '<a href="https://tutorlms.com/pricing?utm_source=tutor_plugin_action_link&utm_medium=wordpress_dashboard&utm_campaign=go_premium" target="_blank">
724 <span style="color: #ff7742; font-weight: bold;">' .
725 __( 'Upgrade to Pro', 'tutor' ) .
726 '</span>
727 </a>';
728 }
729
730 $actions['settings'] = '<a href="admin.php?page=tutor_settings">' . __( 'Settings', 'tutor' ) . '</a>';
731
732 return $actions;
733 }
734
735 /**
736 * Add plugin meta data in WP plugins list page
737 *
738 * @since 1.0.0
739 *
740 * @param array $plugin_meta plugin meta data.
741 * @param string $plugin_file plugin file.
742 *
743 * @return array
744 */
745 public function plugin_row_meta( $plugin_meta, $plugin_file ) {
746
747 if ( tutor()->basename === $plugin_file ) {
748 $plugin_meta[] = sprintf(
749 '<a href="%s"><strong style="color: #03bd24">%s</strong></a>',
750 esc_url( 'https://docs.themeum.com/tutor-lms/?utm_source=tutor&utm_medium=plugins_installation_list&utm_campaign=plugin_docs_link' ),
751 esc_html__( 'Documentation', 'tutor' )
752 );
753 $plugin_meta[] = sprintf(
754 '<a href="%s"><strong style="color: #03bd24">%s</strong></a>',
755 esc_url( 'https://tutorlms.com/support/?utm_source=tutor&utm_medium=plugins_installation_list&utm_campaign=plugin_support_link' ),
756 esc_html__( 'Get Support', 'tutor' )
757 );
758 }
759
760 return $plugin_meta;
761 }
762
763 /**
764 * Add footer text only on tutor pages
765 *
766 * @since 1.0.0
767 *
768 * @param string $footer_text footer text.
769 * @return string
770 */
771 public function admin_footer_text( $footer_text ) {
772 $current_screen = get_current_screen();
773
774 /**
775 * We are making sure that this message will be only on Tutor Admin page
776 */
777 if ( apply_filters( 'tutor_display_admin_footer_text', ( tutor_utils()->array_get( 'parent_base', $current_screen ) === 'tutor' ) ) ) {
778 $footer_text = sprintf(
779 /* translators: %s: plugin name */
780 __( 'If you like %1$s please leave us a %2$s rating. A huge thanks in advance!', 'tutor' ),
781 sprintf( '<strong>%s</strong>', esc_html__( 'Tutor LMS', 'tutor' ) ),
782 '<a href="https://wordpress.org/support/plugin/tutor/reviews?rate=5#new-post" target="_blank" class="tutor-rating-link">&#9733;&#9733;&#9733;&#9733;&#9733;</a>'
783 );
784 }
785
786 return $footer_text;
787 }
788
789 /**
790 * Register course widget
791 *
792 * @since 1.0.0
793 * @return void
794 */
795 public function register_course_widget() {
796 register_widget( Course_Widget::class );
797 }
798
799 /**
800 * Tutor Course List
801 *
802 * @since 2.0.0
803 * @return void
804 */
805 public function tutor_course_list() {
806 include tutor()->path . 'views/pages/course-list.php';
807 }
808
809 /**
810 * Orders view page
811 *
812 * @since 3.0.0
813 *
814 * @return void
815 */
816 public function orders_view() {
817 $current_page = Input::get( 'page' );
818 $action = Input::get( 'action' );
819
820 if ( OrderController::PAGE_SLUG === $current_page && 'edit' === $action ) {
821 ?>
822 <div class="tutor-admin-wrap tutor-order-details-wrapper">
823 <div id="tutor-order-details-root">
824 </div>
825 </div>
826 <?php
827 return;
828 }
829
830 include tutor()->path . 'views/pages/ecommerce/order-list.php';
831 }
832
833 /**
834 * Coupons view page
835 *
836 * @since 3.0.0
837 *
838 * @return void
839 */
840 public function coupons_view() {
841 $action = Input::get( 'action' );
842 if ( in_array( $action, array( 'add_new', 'edit' ) ) ) {
843 ?>
844 <div class="tutor-admin-wrap">
845 <div id="tutor-coupon-root">
846 </div>
847 </div>
848 <?php
849 return;
850 }
851 include tutor()->path . 'views/pages/ecommerce/coupon-list.php';
852 }
853
854 /**
855 * Show welcome page
856 *
857 * @since 1.0.0
858 * @return void
859 */
860 public function welcome_page() {
861 Tutor_Setup::mark_as_visited();
862 include tutor()->path . 'views/pages/welcome.php';
863 exit;
864 }
865
866 /**
867 * Add toolbar items
868 *
869 * @since 1.4.6
870 *
871 * @param \WP_Admin_Bar $admin_bar admin bar object.
872 *
873 * @return mixed
874 */
875 public function add_toolbar_items( \WP_Admin_Bar $admin_bar ) {
876 global $post;
877
878 $course_id = Input::get( 'post', 0, Input::TYPE_INT );
879 $course_post_type = tutor()->course_post_type;
880
881 if ( $admin_bar->get_node( 'new-courses' ) ) {
882 $args = $admin_bar->get_node( 'new-courses' );
883 $args->href = '#';
884 $args->meta['class'] = 'tutor-create-new-course';
885 $admin_bar->add_node( $args );
886 }
887
888 if ( ! tutor_utils()->can_user_edit_course( get_current_user_id(), $course_id ) ) {
889 return $admin_bar;
890 }
891
892 if (
893 ( is_admin() && $post && $course_id && $post->post_type === $course_post_type ) ||
894 ( ! is_admin() && is_single() && $post && $course_post_type === $post->post_type )
895 ) {
896
897 $admin_bar->add_menu(
898 array(
899 'id' => 'edit',
900 'title' => __( 'Edit with Course Builder', 'tutor' ),
901 'href' => tutor_utils()->course_edit_link( $post->ID ),
902 'meta' => array(
903 'title' => __( 'Edit with Course Builder', 'tutor' ),
904 'target' => '_blank',
905 ),
906 )
907 );
908 }
909
910 return $admin_bar;
911 }
912 }
913