PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 3.0.2
Tutor LMS – eLearning and online course solution v3.0.2
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 1 year ago Admin.php 1 year ago Ajax.php 1 year ago Announcements.php 1 year ago Assets.php 1 year ago Backend_Page_Trait.php 1 year ago BaseController.php 1 year ago Course.php 1 year ago Course_Embed.php 3 years ago Course_Filter.php 1 year ago Course_List.php 1 year ago Course_Settings_Tabs.php 1 year ago Course_Widget.php 3 years ago Custom_Validation.php 3 years ago Dashboard.php 1 year ago Earnings.php 1 year ago FormHandler.php 2 years ago Frontend.php 1 year ago Gutenberg.php 1 year ago Input.php 1 year ago Instructor.php 1 year ago Instructors_List.php 1 year ago Lesson.php 1 year ago Options_V2.php 1 year ago Permalink.php 2 years ago Post_types.php 2 years ago Private_Course_Access.php 1 year ago Q_And_A.php 1 year ago Question_Answers_List.php 3 years ago Quiz.php 1 year ago QuizBuilder.php 1 year ago Quiz_Attempts_List.php 1 year ago RestAPI.php 2 years ago Reviews.php 3 years ago Rewrite_Rules.php 2 years ago Shortcode.php 1 year ago Singleton.php 1 year ago Student.php 1 year ago Students_List.php 3 years ago Taxonomies.php 3 years ago Template.php 1 year ago Theme_Compatibility.php 3 years ago Tools.php 3 years ago Tools_V2.php 1 year ago Tutor.php 1 year ago TutorEDD.php 1 year ago Tutor_Base.php 2 years ago Tutor_Setup.php 1 year ago Upgrader.php 1 year ago User.php 1 year ago Utils.php 1 year ago Video_Stream.php 3 years ago WhatsNew.php 2 years ago Withdraw.php 1 year ago Withdraw_Requests_List.php 3 years ago WooCommerce.php 1 year ago
Admin.php
720 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\Traits\JsonResponse;
17
18 if ( ! defined( 'ABSPATH' ) ) {
19 exit;
20 }
21
22 /**
23 * Admin Class
24 *
25 * @since 1.0.0
26 */
27 class Admin {
28 use JsonResponse;
29
30 /**
31 * Constructor
32 *
33 * @since 1.0.0
34 * @return void
35 */
36 public function __construct() {
37
38 add_action( 'admin_notices', array( $this, 'show_unstable_version_admin_notice' ) );
39
40 add_action( 'admin_menu', array( $this, 'register_menu' ) );
41 // Force activate menu for necessary.
42 add_filter( 'parent_file', array( $this, 'parent_menu_active' ) );
43 add_filter( 'submenu_file', array( $this, 'submenu_file_active' ), 10, 2 );
44
45 add_action( 'admin_init', array( $this, 'filter_posts_for_instructors' ) );
46 add_action( 'load-post.php', array( $this, 'check_if_current_users_post' ) );
47
48 add_filter( 'plugin_action_links_' . plugin_basename( TUTOR_FILE ), array( $this, 'plugin_action_links' ) );
49
50 // Plugin Row Meta.
51 add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 );
52
53 // Admin Footer Text.
54 add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ), 1 );
55 // Register Course Widget.
56 add_action( 'widgets_init', array( $this, 'register_course_widget' ) );
57
58 // Handle flash toast message for redirect_to util helper.
59 add_action( 'admin_head', array( new Utils(), 'handle_flash_message' ), 999 );
60 // add_action( 'tutor_after_settings_menu', '\TUTOR\WhatsNew::whats_new_menu', 11 );
61
62 add_action( 'admin_bar_menu', array( $this, 'add_toolbar_items' ), 100 );
63
64 add_action( 'wp_ajax_tutor_do_not_show_feature_page', array( $this, 'handle_do_not_show_feature_page' ) );
65 }
66
67 /**
68 * Show unstable version notice.
69 *
70 * @since 3.0.0
71 *
72 * @return void
73 */
74 public function show_unstable_version_admin_notice() {
75 $version = tutor_utils()->extract_version_details( TUTOR_VERSION );
76 if ( ! $version->is_stable ) {
77 /* translators: %s: version name */
78 $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>' );
79 ?>
80 <div class="notice notice-warning">
81 <p><strong><?php esc_html_e( 'Warning!', 'tutor' ); ?></strong></p>
82 <p><?php echo wp_kses_post( $message ); ?></p>
83 </div>
84 <?php
85 }
86 }
87
88 /**
89 * Register admin menus
90 *
91 * @since 1.0.0
92 * @return void
93 */
94 public function register_menu() {
95 $has_pro = tutor()->has_pro;
96
97 $unanswered_questions = tutor_utils()->unanswered_question_count();
98 $unanswered_bubble = '';
99 if ( $unanswered_questions ) {
100 $unanswered_bubble = '<span class="update-plugins count-' . $unanswered_questions . '"><span class="plugin-count">' . $unanswered_questions . '</span></span>';
101 }
102
103 $course_post_type = tutor()->course_post_type;
104
105 $pro_text = '';
106 if ( $has_pro ) {
107 $pro_text = ' ' . __( 'Pro', 'tutor' );
108 }
109
110 $enable_course_marketplace = (bool) tutor_utils()->get_option( 'enable_course_marketplace' );
111
112 $welcome = Tutor_Setup::is_welcome_page_visited();
113
114 $root_page = array( $this, 'tutor_course_list' );
115 if ( false === $welcome && Input::has( 'page' ) && 'tutor' === Input::get( 'page' ) && Input::has( 'welcome' ) ) {
116 $root_page = array( $this, 'welcome_page' );
117 }
118
119 $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>' );
120 $menu_position = 2;
121
122 add_menu_page(
123 __( 'Tutor LMS', 'tutor' ) . $pro_text,
124 __( 'Tutor LMS', 'tutor' ) . $pro_text,
125 'manage_tutor_instructor',
126 'tutor',
127 $root_page,
128 $icon_base64_uri,
129 $menu_position
130 );
131
132 // Added @since v2.0.0.
133 add_submenu_page( 'tutor', __( 'Courses', 'tutor' ), __( 'Courses', 'tutor' ), 'manage_tutor_instructor', 'tutor', array( $this, 'tutor_course_list' ) );
134
135 if ( '3.0.0' !== get_option( 'tutor-new-feature' ) ) {
136 add_submenu_page( 'tutor', __( 'What\'s New in 3.0', 'tutor' ), sprintf( '<span class="tutor-new-feature tutor-text-orange">%s</span>', __( 'What\'s New in 3.0', 'tutor' ) ), 'manage_tutor', 'tutor-new-feature', array( $this, 'feature_promotion_page' ) );
137 }
138
139 // Ecommerce menu @since 3.0.0.
140 do_action( 'tutor_after_courses_admin_menu' );
141
142 add_submenu_page( 'tutor', __( 'Create Course', 'tutor' ), __( '<span class="tutor-create-course">Create Course</span>', 'tutor' ), 'manage_tutor_instructor', 'create-course', '__return_true' );
143
144 // Extendable action hook @since 2.2.0.
145 do_action( 'tutor_after_courses_menu' );
146
147 add_submenu_page( 'tutor', __( 'Categories', 'tutor' ), __( 'Categories', 'tutor' ), 'manage_tutor', 'edit-tags.php?taxonomy=course-category&post_type=' . $course_post_type, null );
148
149 add_submenu_page( 'tutor', __( 'Tags', 'tutor' ), __( 'Tags', 'tutor' ), 'manage_tutor', 'edit-tags.php?taxonomy=course-tag&post_type=' . $course_post_type, null );
150
151 add_submenu_page( 'tutor', __( 'Students', 'tutor' ), __( 'Students', 'tutor' ), 'manage_tutor', Students_List::STUDENTS_LIST_PAGE, array( $this, 'tutor_students' ) );
152
153 if ( $enable_course_marketplace ) {
154 add_submenu_page( 'tutor', __( 'Instructors', 'tutor' ), __( 'Instructors', 'tutor' ), 'manage_tutor', Instructors_List::INSTRUCTOR_LIST_PAGE, array( $this, 'tutor_instructors' ) );
155 }
156
157 add_submenu_page( 'tutor', __( 'Announcements', 'tutor' ), __( 'Announcements', 'tutor' ), 'manage_tutor_instructor', 'tutor_announcements', array( $this, 'tutor_announcements' ) );
158
159 add_submenu_page( 'tutor', __( 'Q&A', 'tutor' ), __( 'Q&A ', 'tutor' ) . $unanswered_bubble, 'manage_tutor_instructor', Question_Answers_List::QUESTION_ANSWER_PAGE, array( $this, 'question_answer' ) );
160
161 add_submenu_page( 'tutor', __( 'Quiz Attempts', 'tutor' ), __( 'Quiz Attempts', 'tutor' ), 'manage_tutor_instructor', Quiz_Attempts_List::QUIZ_ATTEMPT_PAGE, array( $this, 'quiz_attempts' ) );
162
163 if ( $enable_course_marketplace ) {
164 add_submenu_page( 'tutor', __( 'Withdraw Requests', 'tutor' ), __( 'Withdraw Requests', 'tutor' ), 'manage_tutor', Withdraw_Requests_List::WITHDRAW_REQUEST_LIST_PAGE, array( $this, 'withdraw_requests' ) );
165 }
166
167 add_submenu_page( 'tutor', __( 'Addons', 'tutor' ), __( 'Addons', 'tutor' ), 'manage_tutor', 'tutor-addons', array( $this, 'enable_disable_addons' ) );
168
169 do_action( 'tutor_admin_register' );
170
171 add_submenu_page( 'tutor', __( 'Tools', 'tutor' ), __( 'Tools', 'tutor' ), 'manage_tutor', 'tutor-tools', array( new \TUTOR\Tools_V2(), 'load_tools_page' ) );
172
173 add_submenu_page( 'tutor', __( 'Settings', 'tutor' ), __( 'Settings', 'tutor' ), 'manage_tutor', 'tutor_settings', array( new \TUTOR\Options_V2(), 'load_settings_page' ) );
174
175 do_action( 'tutor_after_settings_menu' );
176
177 if ( ! $has_pro ) {
178 add_submenu_page( 'tutor', __( 'Upgrade to Pro', 'tutor' ), sprintf( '<span class="tutor-get-pro-text">%s</span>', __( 'Upgrade to Pro', 'tutor' ) ), 'manage_options', 'tutor-get-pro', array( $this, 'tutor_get_pro' ) );
179 }
180 }
181
182 /**
183 * Welcome page opt-out
184 *
185 * @since 3.0.0
186 */
187 public function handle_do_not_show_feature_page() {
188 tutor_utils()->check_nonce();
189
190 if ( ! User::is_admin() ) {
191 $this->json_response(
192 tutor_utils()->error_message(),
193 null,
194 HttpHelper::STATUS_BAD_REQUEST
195 );
196 }
197
198 update_option( 'tutor-new-feature', '3.0.0' );
199 $this->json_response( __( 'Success', 'tutor' ) );
200 }
201
202 /**
203 * Show Feature Promotion Page for Free User.
204 *
205 * @since 2.2.0
206 *
207 * @return void
208 */
209 public function feature_promotion_page() {
210 include tutor()->path . 'views/pages/welcome.php';
211 // include tutor()->path . 'views/pages/feature-promotion.php';
212 }
213
214 /**
215 * Show students page
216 *
217 * @since 1.0.0
218 * @return void
219 */
220 public function tutor_students() {
221 include tutor()->path . 'views/pages/students.php';
222 }
223
224 /**
225 * Show instructor page
226 *
227 * @since 1.0.0
228 * @return void
229 */
230 public function tutor_instructors() {
231 include tutor()->path . 'views/pages/instructors.php';
232 }
233
234 /**
235 * Show announcements page
236 *
237 * @since 1.0.0
238 * @return void
239 */
240 public function tutor_announcements() {
241 include tutor()->path . 'views/pages/announcements.php';
242 }
243
244 /**
245 * Show Q&A page
246 *
247 * @since 1.0.0
248 * @return void
249 */
250 public function question_answer() {
251 include tutor()->path . 'views/pages/question_answer.php';
252 }
253
254 /**
255 * Show quiz attempts page
256 *
257 * @since 1.0.0
258 * @return void
259 */
260 public function quiz_attempts() {
261 include tutor()->path . 'views/pages/quiz_attempts.php';
262 }
263
264 /**
265 * Show the withdraw requests table
266 *
267 * @since 1.2.0
268 * @return void
269 */
270 public function withdraw_requests() {
271 include tutor()->path . 'views/pages/withdraw_requests.php';
272 }
273
274 /**
275 * Enable or disable addons
276 *
277 * @since 1.0.0
278 * @return void
279 */
280 public function enable_disable_addons() {
281
282 if ( defined( 'TUTOR_PRO_VERSION' ) ) {
283 include tutor()->path . 'views/pages/enable_disable_addons.php';
284 } else {
285 include tutor()->path . 'views/pages/tutor-pro-addons.php';
286 }
287 }
288
289 /**
290 * Tutor tools page (OLD)
291 *
292 * @since 1.0.0
293 * @return void
294 */
295 public function tutor_tools_old() {
296 $tutor_admin_tools_page = Input::get( 'tutor_admin_tools_page' );
297 if ( $tutor_admin_tools_page ) {
298 include apply_filters( 'tutor_admin_tools_page', tutor()->path . "views/pages/{$tutor_admin_tools_page}.php", $tutor_admin_tools_page );
299 } else {
300 $pages = apply_filters(
301 'tutor_tool_pages',
302 array(
303 'tutor_pages' => array( 'title' => __( 'Tutor Pages', 'tutor' ) ),
304 'status' => __( 'Status', 'tutor' ),
305 )
306 );
307
308 $current_page = 'tutor_pages';
309 $requested_page = Input::get( 'sub_page' );
310 if ( $requested_page ) {
311 $current_page = $requested_page;
312 }
313
314 $current_page = str_replace( '/', '', $current_page );
315 $current_page = str_replace( '.', '', $current_page );
316 $current_page = str_replace( '\\', '', $current_page );
317 $current_page = trim( $current_page );
318
319 include tutor()->path . 'views/pages/tools.php';
320 }
321 }
322
323 /**
324 * Show pro upgrade page
325 *
326 * @since 1.0.0
327 * @return void
328 */
329 public function tutor_get_pro() {
330 include tutor()->path . 'views/pages/get-pro.php';
331 }
332
333 /**
334 * Parent menu active
335 *
336 * @since 1.0.0
337 *
338 * @param string $parent_file parent file.
339 * @return string
340 */
341 public function parent_menu_active( $parent_file ) {
342 $taxonomy = Input::get( 'taxonomy' );
343 if ( 'course-category' === $taxonomy || 'course-tag' === $taxonomy ) {
344 return 'tutor';
345 }
346
347 return $parent_file;
348 }
349
350 /**
351 * Sub-menu active
352 *
353 * @since 1.0.0
354 *
355 * @param string $submenu_file submenu file.
356 * @param string $parent_file parent file.
357 *
358 * @return string
359 */
360 public function submenu_file_active( $submenu_file, $parent_file ) {
361 $taxonomy = Input::get( 'taxonomy' );
362 $course_post_type = tutor()->course_post_type;
363
364 if ( 'course-category' === $taxonomy ) {
365 return 'edit-tags.php?taxonomy=course-category&post_type=' . $course_post_type;
366 }
367 if ( 'course-tag' === $taxonomy ) {
368 return 'edit-tags.php?taxonomy=course-tag&post_type=' . $course_post_type;
369 }
370
371 return $submenu_file;
372 }
373
374 /**
375 * Filter posts for instructor
376 *
377 * @since 1.0.0
378 * @return void
379 */
380 public function filter_posts_for_instructors() {
381 if ( ! current_user_can( 'administrator' ) && current_user_can( tutor()->instructor_role ) ) {
382 @remove_menu_page( 'edit-comments.php' ); // Comments.
383 add_filter( 'posts_clauses_request', array( $this, 'posts_clauses_request' ) );
384 }
385 }
386
387 /**
388 * Request for posts clauses
389 *
390 * @since 1.0.0
391 *
392 * @param mixed $clauses clauses.
393 * @return mixed
394 */
395 public function posts_clauses_request( $clauses ) {
396
397 if ( ! is_admin() || ( ! Input::has( 'post_type' ) || Input::get( 'post_type' ) != tutor()->course_post_type ) || tutor_utils()->has_user_role( array( 'administrator', 'editor' ) ) ) {
398 return $clauses;
399 }
400
401 // Need multi instructor check.
402 global $wpdb;
403
404 $user_id = get_current_user_id();
405
406 $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 ) );
407 $own_courses = is_array( $get_assigned_courses_ids ) ? $get_assigned_courses_ids : array();
408
409 $in_query_pre = count( $own_courses ) ? implode( ',', $own_courses ) : null;
410 $in_query_where = $in_query_pre ? " OR {$wpdb->posts}.ID IN({$in_query_pre})" : '';
411
412 $course_post_type = tutor()->course_post_type;
413 $custom_author_query = " AND ({$wpdb->posts}.post_type!='{$course_post_type}' OR {$wpdb->posts}.post_author = {$user_id}) {$in_query_where}";
414
415 $clauses['where'] .= $custom_author_query;
416
417 return $clauses;
418 }
419
420 /**
421 * Prevent unauthorised course/lesson edit page by direct URL
422 *
423 * @since 1.0.0
424 * @return void
425 */
426 public function check_if_current_users_post() {
427 if ( current_user_can( 'administrator' ) || ! current_user_can( tutor()->instructor_role ) ) {
428 return;
429 }
430
431 if ( ! empty( Input::get( 'post' ) ) ) {
432 $get_post_id = Input::get( 'post', Input::TYPE_INT );
433 $get_post = get_post( $get_post_id );
434 $tutor_post_types = array( tutor()->course_post_type, tutor()->lesson_post_type );
435
436 $current_user = get_current_user_id();
437
438 if ( in_array( $get_post->post_type, $tutor_post_types ) && $get_post->post_author != $current_user ) {
439 global $wpdb;
440
441 $get_assigned_courses_ids = (int) $wpdb->get_var(
442 $wpdb->prepare(
443 "SELECT user_id
444 from {$wpdb->usermeta}
445 WHERE user_id = %d AND meta_key = '_tutor_instructor_course_id' AND meta_value = %d ",
446 $current_user,
447 $get_post_id
448 )
449 );
450
451 if ( ! $get_assigned_courses_ids ) {
452 wp_die( esc_html__( 'Permission Denied', 'tutor' ) );
453 }
454 }
455 }
456 }
457
458 /**
459 * Scan template files
460 *
461 * @since 1.0.0
462 *
463 * @param string $template_path template file path.
464 * @return array
465 */
466 public static function scan_template_files( $template_path = null ) {
467 if ( ! $template_path ) {
468 $template_path = tutor()->path . 'templates/';
469 }
470
471 $files = @scandir($template_path); // @codingStandardsIgnoreLine.
472 $result = array();
473
474 if ( ! empty( $files ) ) {
475 foreach ( $files as $key => $value ) {
476 if ( ! in_array( $value, array( '.', '..', '.DS_Store' ), true ) ) {
477 if ( is_dir( $template_path . DIRECTORY_SEPARATOR . $value ) ) {
478 $sub_files = self::scan_template_files( $template_path . DIRECTORY_SEPARATOR . $value );
479 foreach ( $sub_files as $sub_file ) {
480 $result[] = $value . DIRECTORY_SEPARATOR . $sub_file;
481 }
482 } else {
483 $result[] = $value;
484 }
485 }
486 }
487 }
488 return $result;
489 }
490
491 /**
492 * Get Template overridden files
493 *
494 * @since 1.0.0
495 * @return array
496 */
497 public static function template_overridden_files() {
498 $template_files = self::scan_template_files();
499
500 $override_files = array();
501 foreach ( $template_files as $file ) {
502 $file_path = null;
503 if ( file_exists( trailingslashit( get_stylesheet_directory() ) . tutor()->template_path . $file ) ) {
504 $file_path = $file;
505 } elseif ( file_exists( trailingslashit( get_template_directory() ) . tutor()->template_path . $file ) ) {
506 $file_path = $file;
507 }
508
509 if ( $file_path ) {
510 $override_files[] = str_replace( WP_CONTENT_DIR . '/themes/', '', $file_path );
511 }
512 }
513
514 return $override_files;
515 }
516
517 /**
518 * Plugin activation link
519 *
520 * @since 1.0.0
521 *
522 * @param array $actions action list.
523 * @return array
524 */
525 public function plugin_action_links( $actions ) {
526 $has_pro = tutor()->has_pro;
527
528 if ( ! $has_pro ) {
529 $actions['tutor_pro_link'] =
530 '<a href="https://tutorlms.com/pricing?utm_source=tutor_plugin_action_link&utm_medium=wordpress_dashboard&utm_campaign=go_premium" target="_blank">
531 <span style="color: #ff7742; font-weight: bold;">' .
532 __( 'Upgrade to Pro', 'wp-megamenu' ) .
533 '</span>
534 </a>';
535 }
536
537 $actions['settings'] = '<a href="admin.php?page=tutor_settings">' . __( 'Settings', 'tutor' ) . '</a>';
538
539 return $actions;
540 }
541
542 /**
543 * Add plugin meta data in WP plugins list page
544 *
545 * @since 1.0.0
546 *
547 * @param array $plugin_meta plugin meta data.
548 * @param string $plugin_file plugin file.
549 *
550 * @return array
551 */
552 public function plugin_row_meta( $plugin_meta, $plugin_file ) {
553
554 if ( tutor()->basename === $plugin_file ) {
555 $plugin_meta[] = sprintf(
556 '<a href="%s">%s</a>',
557 esc_url( 'https://docs.themeum.com/tutor-lms/?utm_source=tutor&utm_medium=plugins_installation_list&utm_campaign=plugin_docs_link' ),
558 __( '<strong style="color: #03bd24">Documentation</strong>', 'tutor' )
559 );
560 $plugin_meta[] = sprintf(
561 '<a href="%s">%s</a>',
562 esc_url( 'https://www.themeum.com/contact-us/?utm_source=tutor&utm_medium=plugins_installation_list&utm_campaign=plugin_support_link' ),
563 __( '<strong style="color: #03bd24">Get Support</strong>', 'tutor' )
564 );
565 }
566
567 return $plugin_meta;
568 }
569
570 /**
571 * Add footer text only on tutor pages
572 *
573 * @since 1.0.0
574 *
575 * @param string $footer_text footer text.
576 * @return string
577 */
578 public function admin_footer_text( $footer_text ) {
579 $current_screen = get_current_screen();
580
581 /**
582 * We are making sure that this message will be only on Tutor Admin page
583 */
584 if ( apply_filters( 'tutor_display_admin_footer_text', ( tutor_utils()->array_get( 'parent_base', $current_screen ) === 'tutor' ) ) ) {
585 $footer_text = sprintf(
586 /* translators: %s: plugin name */
587 __( 'If you like %1$s please leave us a %2$s rating. A huge thanks in advance!', 'tutor' ),
588 sprintf( '<strong>%s</strong>', esc_html__( 'Tutor LMS', 'tutor' ) ),
589 '<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>'
590 );
591 }
592
593 return $footer_text;
594 }
595
596 /**
597 * Register course widget
598 *
599 * @since 1.0.0
600 * @return void
601 */
602 public function register_course_widget() {
603 register_widget( 'Tutor\Course_Widget' );
604 }
605
606 /**
607 * Tutor Course List
608 *
609 * @since 2.0.0
610 * @return void
611 */
612 public function tutor_course_list() {
613 include tutor()->path . 'views/pages/course-list.php';
614 }
615
616 /**
617 * Orders view page
618 *
619 * @since 3.0.0
620 *
621 * @return void
622 */
623 public function orders_view() {
624 $current_page = Input::get( 'page' );
625 $action = Input::get( 'action' );
626
627 if ( OrderController::PAGE_SLUG === $current_page && 'edit' === $action ) {
628 ?>
629 <div class="tutor-admin-wrap tutor-order-details-wrapper">
630 <div id="tutor-order-details-root">
631 </div>
632 </div>
633 <?php
634 return;
635 }
636
637 include tutor()->path . 'views/pages/ecommerce/order-list.php';
638 }
639
640 /**
641 * Coupons view page
642 *
643 * @since 3.0.0
644 *
645 * @return void
646 */
647 public function coupons_view() {
648 $action = Input::get( 'action' );
649 if ( in_array( $action, array( 'add_new', 'edit' ) ) ) {
650 ?>
651 <div class="tutor-admin-wrap">
652 <div id="tutor-coupon-root">
653 </div>
654 </div>
655 <?php
656 return;
657 }
658 include tutor()->path . 'views/pages/ecommerce/coupon-list.php';
659 }
660
661 /**
662 * Show welcome page
663 *
664 * @since 1.0.0
665 * @return void
666 */
667 public function welcome_page() {
668 Tutor_Setup::mark_as_visited();
669 include tutor()->path . 'views/pages/welcome.php';
670 exit;
671 }
672
673 /**
674 * Add toolbar items
675 *
676 * @since 1.4.6
677 *
678 * @param \WP_Admin_Bar $admin_bar admin bar object.
679 *
680 * @return mixed
681 */
682 public function add_toolbar_items( \WP_Admin_Bar $admin_bar ) {
683 global $post;
684
685 $course_id = Input::get( 'post', 0, Input::TYPE_INT );
686 $course_post_type = tutor()->course_post_type;
687
688 if ( ! tutor_utils()->can_user_edit_course( get_current_user_id(), $course_id ) ) {
689 return $admin_bar;
690 }
691
692 if ( $admin_bar->get_node( 'new-courses' ) ) {
693 $args = $admin_bar->get_node( 'new-courses' );
694 $args->href = '#';
695 $args->meta['class'] = 'tutor-create-new-course';
696 $admin_bar->add_node( $args );
697 }
698
699 if (
700 ( is_admin() && $post && $course_id && $post->post_type === $course_post_type ) ||
701 ( ! is_admin() && is_single() && $post && $course_post_type === $post->post_type )
702 ) {
703
704 $admin_bar->add_menu(
705 array(
706 'id' => 'edit',
707 'title' => __( 'Edit with Course Builder', 'tutor' ),
708 'href' => tutor_utils()->course_edit_link( $post->ID ),
709 'meta' => array(
710 'title' => __( 'Edit with Course Builder', 'tutor' ),
711 'target' => '_blank',
712 ),
713 )
714 );
715 }
716
717 return $admin_bar;
718 }
719 }
720