PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 2.1.2
Tutor LMS – eLearning and online course solution v2.1.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 3 years ago Admin.php 3 years ago Ajax.php 3 years ago Announcements.php 3 years ago Assets.php 3 years ago Backend_Page_Trait.php 3 years ago Course.php 3 years ago Course_Embed.php 3 years ago Course_Filter.php 3 years ago Course_List.php 3 years ago Course_Settings_Tabs.php 3 years ago Course_Widget.php 4 years ago Custom_Validation.php 4 years ago Dashboard.php 3 years ago FormHandler.php 4 years ago Frontend.php 3 years ago Gutenberg.php 3 years ago Input.php 3 years ago Instructor.php 4 years ago Instructors_List.php 3 years ago Lesson.php 3 years ago Options_V2.php 3 years ago Post_types.php 3 years ago Private_Course_Access.php 4 years ago Q_and_A.php 3 years ago Question_Answers_List.php 4 years ago Quiz.php 3 years ago Quiz_Attempts_List.php 3 years ago RestAPI.php 4 years ago Reviews.php 3 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 3 years ago Theme_Compatibility.php 5 years ago Tools.php 3 years ago Tools_V2.php 4 years ago Tutor.php 3 years ago TutorEDD.php 4 years ago Tutor_Base.php 5 years ago Tutor_List_Table.php 3 years ago Tutor_Setup.php 3 years ago Upgrader.php 4 years ago User.php 4 years ago Utils.php 3 years ago Video_Stream.php 4 years ago Withdraw.php 3 years ago Withdraw_Requests_List.php 3 years ago WooCommerce.php 3 years ago
Admin.php
621 lines
1 <?php
2 /**
3 * Class Admin
4 *
5 * @author themeum
6 * @link https://themeum.com
7 * @package Tutor
8 * @since v.1.0.0
9 */
10
11 namespace TUTOR;
12
13 use TUTOR\Input;
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit;
17 }
18
19 /**
20 * Admin Class
21 *
22 * @since 1.0.0
23 */
24 class Admin {
25 /**
26 * Constructor
27 */
28 public function __construct() {
29 add_action( 'admin_menu', array( $this, 'register_menu' ) );
30 // Force activate menu for necessary.
31 add_filter( 'parent_file', array( $this, 'parent_menu_active' ) );
32 add_filter( 'submenu_file', array( $this, 'submenu_file_active' ), 10, 2 );
33
34 add_action( 'admin_init', array( $this, 'filter_posts_for_instructors' ) );
35 add_action( 'load-post.php', array( $this, 'check_if_current_users_post' ) );
36
37 add_action( 'admin_action_uninstall_tutor_and_erase', array( $this, 'erase_tutor_data' ) );
38 add_filter( 'plugin_action_links_' . plugin_basename( TUTOR_FILE ), array( $this, 'plugin_action_links' ) );
39
40 // Plugin Row Meta.
41 add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 );
42
43 // Admin Footer Text.
44 add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ), 1 );
45 // Register Course Widget.
46 add_action( 'widgets_init', array( $this, 'register_course_widget' ) );
47
48 // Handle flash toast message for redirect_to util helper.
49 add_action( 'admin_head', array( new Utils(), 'handle_flash_message' ), 999 );
50 }
51
52 /**
53 * Register admin menus
54 *
55 * @return void
56 * @since 1.0.0
57 */
58 public function register_menu() {
59 $has_pro = tutor()->has_pro;
60
61 $unanswered_questions = tutor_utils()->unanswered_question_count();
62 $unanswered_bubble = '';
63 if ( $unanswered_questions ) {
64 $unanswered_bubble = '<span class="update-plugins count-' . $unanswered_questions . '"><span class="plugin-count">' . $unanswered_questions . '</span></span>';
65 }
66
67 $course_post_type = tutor()->course_post_type;
68
69 $pro_text = '';
70 if ( $has_pro ) {
71 $pro_text = ' ' . __( 'Pro', 'tutor' );
72 }
73
74 $enable_course_marketplace = (bool) tutor_utils()->get_option( 'enable_course_marketplace' );
75
76 $welcome = Tutor_Setup::is_welcome_page_visited();
77
78 $root_page = array( $this, 'tutor_course_list' );
79 if ( false === $welcome && Input::has( 'page' ) && 'tutor' === Input::get( 'page' ) && Input::has( 'welcome' ) ) {
80 $root_page = array( $this, 'welcome_page' );
81 }
82
83 $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>' );
84 $menu_position = 2;
85
86 add_menu_page(
87 __( 'Tutor LMS', 'tutor' ) . $pro_text,
88 __( 'Tutor LMS', 'tutor' ) . $pro_text,
89 'manage_tutor_instructor',
90 'tutor',
91 $root_page,
92 $icon_base64_uri,
93 $menu_position
94 );
95
96 // Added @since v2.0.0.
97 add_submenu_page( 'tutor', __( 'Courses', 'tutor' ), __( 'Courses', 'tutor' ), 'manage_tutor_instructor', 'tutor', array( $this, 'tutor_course_list' ) );
98
99 add_submenu_page( 'tutor', __( 'Categories', 'tutor' ), __( 'Categories', 'tutor' ), 'manage_tutor', 'edit-tags.php?taxonomy=course-category&post_type=' . $course_post_type, null );
100
101 add_submenu_page( 'tutor', __( 'Tags', 'tutor' ), __( 'Tags', 'tutor' ), 'manage_tutor', 'edit-tags.php?taxonomy=course-tag&post_type=' . $course_post_type, null );
102
103 add_submenu_page( 'tutor', __( 'Students', 'tutor' ), __( 'Students', 'tutor' ), 'manage_tutor', Students_List::STUDENTS_LIST_PAGE, array( $this, 'tutor_students' ) );
104
105 if ( $enable_course_marketplace ) {
106 add_submenu_page( 'tutor', __( 'Instructors', 'tutor' ), __( 'Instructors', 'tutor' ), 'manage_tutor', Instructors_List::INSTRUCTOR_LIST_PAGE, array( $this, 'tutor_instructors' ) );
107 }
108
109 add_submenu_page( 'tutor', __( 'Announcements', 'tutor' ), __( 'Announcements', 'tutor' ), 'manage_tutor_instructor', 'tutor_announcements', array( $this, 'tutor_announcements' ) );
110
111 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' ) );
112
113 add_submenu_page( 'tutor', __( 'Quiz Attempts', 'tutor' ), __( 'Quiz Attempts', 'tutor' ), 'manage_tutor_instructor', Quiz_Attempts_List::QUIZ_ATTEMPT_PAGE, array( $this, 'quiz_attempts' ) );
114
115 if ( $enable_course_marketplace ) {
116 add_submenu_page( 'tutor', __( 'Withdraw Requests', 'tutor' ), __( 'Withdraw Requests', 'tutor' ), 'manage_tutor', Withdraw_Requests_List::WITHDRAW_REQUEST_LIST_PAGE, array( $this, 'withdraw_requests' ) );
117 }
118
119 add_submenu_page( 'tutor', __( 'Add-ons', 'tutor' ), __( 'Add-ons', 'tutor' ), 'manage_tutor', 'tutor-addons', array( $this, 'enable_disable_addons' ) );
120
121 do_action( 'tutor_admin_register' );
122
123 add_submenu_page( 'tutor', __( 'Tools', 'tutor' ), __( 'Tools', 'tutor' ), 'manage_tutor', 'tutor-tools', array( new \TUTOR\Tools_V2(), 'load_tools_page' ) );
124
125 add_submenu_page( 'tutor', __( 'Settings', 'tutor' ), __( 'Settings', 'tutor' ), 'manage_tutor', 'tutor_settings', array( new \TUTOR\Options_V2(), 'load_settings_page' ) );
126
127 if ( ! $has_pro ) {
128 add_submenu_page( 'tutor', __( 'Get Pro', 'tutor' ), __( '<span class="dashicons dashicons-awards tutor-get-pro-text"></span> Get Pro', 'tutor' ), 'manage_options', 'tutor-get-pro', array( $this, 'tutor_get_pro' ) );
129 }
130 }
131
132 /**
133 * Show students page
134 *
135 * @return void
136 * @since 1.0.0
137 */
138 public function tutor_students() {
139 include tutor()->path . 'views/pages/students.php';
140 }
141
142 /**
143 * Show instructor page
144 *
145 * @return void
146 * @since 1.0.0
147 */
148 public function tutor_instructors() {
149 include tutor()->path . 'views/pages/instructors.php';
150 }
151
152 /**
153 * Show announcements page
154 *
155 * @return void
156 * @since 1.0.0
157 */
158 public function tutor_announcements() {
159 include tutor()->path . 'views/pages/announcements.php';
160 }
161
162 /**
163 * Show Q&A page
164 *
165 * @return void
166 * @since 1.0.0
167 */
168 public function question_answer() {
169 include tutor()->path . 'views/pages/question_answer.php';
170 }
171
172 /**
173 * Show quiz attempts page
174 *
175 * @return void
176 * @since 1.0.0
177 */
178 public function quiz_attempts() {
179 include tutor()->path . 'views/pages/quiz_attempts.php';
180 }
181
182 /**
183 * Show the withdraw requests table
184 *
185 * @since v.1.2.0
186 */
187 public function withdraw_requests() {
188 include tutor()->path . 'views/pages/withdraw_requests.php';
189 }
190
191 /**
192 * Enable or disable addons
193 *
194 * @return void
195 * @since 1.0.0
196 */
197 public function enable_disable_addons() {
198
199 if ( defined( 'TUTOR_PRO_VERSION' ) ) {
200 include tutor()->path . 'views/pages/enable_disable_addons.php';
201 } else {
202 include tutor()->path . 'views/pages/tutor-pro-addons.php';
203 }
204 }
205
206 /**
207 * Tutor tools page (OLD)
208 *
209 * @return void
210 * @since 1.0.0
211 */
212 public function tutor_tools_old() {
213 $tutor_admin_tools_page = Input::get( 'tutor_admin_tools_page' );
214 if ( $tutor_admin_tools_page ) {
215 include apply_filters( 'tutor_admin_tools_page', tutor()->path . "views/pages/{$tutor_admin_tools_page}.php", $tutor_admin_tools_page );
216 } else {
217 $pages = apply_filters(
218 'tutor_tool_pages',
219 array(
220 'tutor_pages' => array( 'title' => __( 'Tutor Pages', 'tutor' ) ),
221 'status' => __( 'Status', 'tutor' ),
222 )
223 );
224
225 $current_page = 'tutor_pages';
226 $requested_page = Input::get( 'sub_page' );
227 if ( $requested_page ) {
228 $current_page = $requested_page;
229 }
230
231 $current_page = str_replace( '/', '', $current_page );
232 $current_page = str_replace( '.', '', $current_page );
233 $current_page = str_replace( '\\', '', $current_page );
234 $current_page = trim( $current_page );
235
236 include tutor()->path . 'views/pages/tools.php';
237 }
238 }
239
240 /**
241 * Show pro upgrade page
242 *
243 * @return void
244 * @since 1.0.0
245 */
246 public function tutor_get_pro() {
247 include tutor()->path . 'views/pages/get-pro.php';
248 }
249
250 /**
251 * Parent menu active
252 *
253 * @param string $parent_file parent file.
254 * @return string
255 * @since 1.0.0
256 */
257 public function parent_menu_active( $parent_file ) {
258 $taxonomy = Input::get( 'taxonomy' );
259 if ( 'course-category' === $taxonomy || 'course-tag' === $taxonomy ) {
260 return 'tutor';
261 }
262
263 return $parent_file;
264 }
265
266 /**
267 * Sub-menu active
268 *
269 * @param string $submenu_file submenu file.
270 * @param string $parent_file parent file.
271 * @return string
272 * @since 1.0.0
273 */
274 public function submenu_file_active( $submenu_file, $parent_file ) {
275 $taxonomy = Input::get( 'taxonomy' );
276 $course_post_type = tutor()->course_post_type;
277
278 if ( 'course-category' === $taxonomy ) {
279 return 'edit-tags.php?taxonomy=course-category&post_type=' . $course_post_type;
280 }
281 if ( 'course-tag' === $taxonomy ) {
282 return 'edit-tags.php?taxonomy=course-tag&post_type=' . $course_post_type;
283 }
284
285 return $submenu_file;
286 }
287
288 /**
289 * Filter posts for instructor
290 *
291 * @return void
292 * @since 1.0.0
293 */
294 public function filter_posts_for_instructors() {
295 if ( ! current_user_can( 'administrator' ) && current_user_can( tutor()->instructor_role ) ) {
296 @remove_menu_page( 'edit-comments.php' ); // Comments.
297 add_filter( 'posts_clauses_request', array( $this, 'posts_clauses_request' ) );
298 }
299 }
300
301 /**
302 * Request for posts clauses
303 *
304 * @param mixed $clauses clauses.
305 * @return mixed
306 * @since 1.0.0
307 */
308 public function posts_clauses_request( $clauses ) {
309
310 if ( ! is_admin() || ( ! Input::has( 'post_type' ) || Input::get( 'post_type' ) != tutor()->course_post_type ) || tutor_utils()->has_user_role( array( 'administrator', 'editor' ) ) ) {
311 return $clauses;
312 }
313
314 // Need multi instructor check.
315 global $wpdb;
316
317 $user_id = get_current_user_id();
318
319 $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 ) );
320 $own_courses = is_array( $get_assigned_courses_ids ) ? $get_assigned_courses_ids : array();
321
322 $in_query_pre = count( $own_courses ) ? implode( ',', $own_courses ) : null;
323 $in_query_where = $in_query_pre ? " OR {$wpdb->posts}.ID IN({$in_query_pre})" : '';
324
325 $course_post_type = tutor()->course_post_type;
326 $custom_author_query = " AND ({$wpdb->posts}.post_type!='{$course_post_type}' OR {$wpdb->posts}.post_author = {$user_id}) {$in_query_where}";
327
328 $clauses['where'] .= $custom_author_query;
329
330 return $clauses;
331 }
332
333 /**
334 * Prevent unauthorised course/lesson edit page by direct URL
335 *
336 * @since v.1.0.0
337 */
338 public function check_if_current_users_post() {
339 if ( current_user_can( 'administrator' ) || ! current_user_can( tutor()->instructor_role ) ) {
340 return;
341 }
342
343 if ( ! empty( Input::get( 'post' ) ) ) {
344 $get_post_id = Input::get( 'post', Input::TYPE_INT );
345 $get_post = get_post( $get_post_id );
346 $tutor_post_types = array( tutor()->course_post_type, tutor()->lesson_post_type );
347
348 $current_user = get_current_user_id();
349
350 if ( in_array( $get_post->post_type, $tutor_post_types ) && $get_post->post_author != $current_user ) {
351 global $wpdb;
352
353 $get_assigned_courses_ids = (int) $wpdb->get_var(
354 $wpdb->prepare(
355 "SELECT user_id
356 from {$wpdb->usermeta}
357 WHERE user_id = %d AND meta_key = '_tutor_instructor_course_id' AND meta_value = %d ",
358 $current_user,
359 $get_post_id
360 )
361 );
362
363 if ( ! $get_assigned_courses_ids ) {
364 wp_die( esc_html__( 'Permission Denied', 'tutor' ) );
365 }
366 }
367 }
368 }
369
370 /**
371 * Scan template files
372 *
373 * @param string $template_path template file path.
374 * @return array
375 * @since 1.0.0
376 */
377 public static function scan_template_files( $template_path = null ) {
378 if ( ! $template_path ) {
379 $template_path = tutor()->path . 'templates/';
380 }
381
382 $files = @scandir($template_path); // @codingStandardsIgnoreLine.
383 $result = array();
384
385 if ( ! empty( $files ) ) {
386 foreach ( $files as $key => $value ) {
387 if ( ! in_array( $value, array( '.', '..', '.DS_Store' ), true ) ) {
388 if ( is_dir( $template_path . DIRECTORY_SEPARATOR . $value ) ) {
389 $sub_files = self::scan_template_files( $template_path . DIRECTORY_SEPARATOR . $value );
390 foreach ( $sub_files as $sub_file ) {
391 $result[] = $value . DIRECTORY_SEPARATOR . $sub_file;
392 }
393 } else {
394 $result[] = $value;
395 }
396 }
397 }
398 }
399 return $result;
400 }
401
402 /**
403 * Get Template overridden files
404 *
405 * @return array
406 * @since 1.0.0
407 */
408 public static function template_overridden_files() {
409 $template_files = self::scan_template_files();
410
411 $override_files = array();
412 foreach ( $template_files as $file ) {
413 $file_path = null;
414 if ( file_exists( trailingslashit( get_stylesheet_directory() ) . tutor()->template_path . $file ) ) {
415 $file_path = $file;
416 } elseif ( file_exists( trailingslashit( get_template_directory() ) . tutor()->template_path . $file ) ) {
417 $file_path = $file;
418 }
419
420 if ( $file_path ) {
421 $override_files[] = str_replace( WP_CONTENT_DIR . '/themes/', '', $file_path );
422 }
423 }
424
425 return $override_files;
426 }
427
428 /**
429 * Erase tutor data
430 *
431 * @return void
432 * @since 1.0.0
433 */
434 public function erase_tutor_data() {
435 global $wpdb;
436
437 $is_erase_data = tutor_utils()->get_option( 'delete_on_uninstall' );
438 // Deleting Data.
439
440 $plugin_file = tutor()->basename;
441 if ( $is_erase_data && current_user_can( 'deactivate_plugin', $plugin_file ) ) {
442 /**
443 * Deleting Post Type, Meta Data, taxonomy
444 */
445 $course_post_type = tutor()->course_post_type;
446 $lesson_post_type = tutor()->lesson_post_type;
447
448 $post_types = array(
449 $course_post_type,
450 $lesson_post_type,
451 'tutor_quiz',
452 'tutor_enrolled',
453 'topics',
454 'tutor_enrolled',
455 'tutor_announcements',
456 );
457
458 $post_type_strings = "'" . implode( "','", $post_types ) . "'";
459 $tutor_posts = $wpdb->get_col( "SELECT ID from {$wpdb->posts} WHERE post_type in({$post_type_strings}) ;" ); //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
460
461 if ( is_array( $tutor_posts ) && count( $tutor_posts ) ) {
462 foreach ( $tutor_posts as $post_id ) {
463 // Delete categories.
464 $terms = wp_get_object_terms( $post_id, 'course-category' );
465 foreach ( $terms as $term ) {
466 wp_remove_object_terms( $post_id, array( $term->term_id ), 'course-category' );
467 }
468
469 // Delete tags if available.
470 $terms = wp_get_object_terms( $post_id, 'course-tag' );
471 foreach ( $terms as $term ) {
472 wp_remove_object_terms( $post_id, array( $term->term_id ), 'course-tag' );
473 }
474
475 // Delete All Meta.
476 $wpdb->delete( $wpdb->postmeta, array( 'post_id' => $post_id ) );
477 $wpdb->delete( $wpdb->posts, array( 'ID' => $post_id ) );
478 }
479 }
480
481 /**
482 * Deleting Comments (reviews, questions, quiz_answers, etc)
483 */
484 $tutor_comments = $wpdb->get_col( "SELECT comment_ID from {$wpdb->comments} WHERE comment_agent = 'comment_agent' ;" );
485 $comments_ids_strings = "'" . implode( "','", $tutor_comments ) . "'";
486 if ( is_array( $tutor_comments ) && count( $tutor_comments ) ) {
487 $wpdb->query( "DELETE from {$wpdb->commentmeta} WHERE comment_ID in({$comments_ids_strings}) " ); //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
488 }
489 $wpdb->delete( $wpdb->comments, array( 'comment_agent' => 'comment_agent' ) );
490
491 /**
492 * Delete Options
493 */
494
495 delete_option( 'tutor_option' );
496 $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => '_is_tutor_student' ) );
497 $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => '_tutor_instructor_approved' ) );
498 $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => '_tutor_instructor_status' ) );
499 $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => '_is_tutor_instructor' ) );
500 $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE '%_tutor_completed_lesson_id_%' " );
501
502 // Deleting Table.
503 $prefix = $wpdb->prefix;
504 //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
505 $wpdb->query( "DROP TABLE IF EXISTS {$prefix}tutor_quiz_attempts, {$prefix}tutor_quiz_attempt_answers, {$prefix}tutor_quiz_questions, {$prefix}tutor_quiz_question_answers, {$prefix}tutor_earnings, {$prefix}tutor_withdraws " );
506
507 deactivate_plugins( $plugin_file );
508 }
509
510 wp_redirect( 'plugins.php' );
511 die();
512 }
513
514 /**
515 * Plugin activation link
516 *
517 * @param array $actions action list.
518 * @return array
519 * @since 1.0.0
520 */
521 public function plugin_action_links( $actions ) {
522 $has_pro = tutor()->has_pro;
523
524 if ( ! $has_pro ) {
525 $actions['tutor_pro_link'] =
526 '<a href="https://www.themeum.com/product/tutor-lms/#pricing?utm_source=tutor_plugin_action_link&utm_medium=wordpress_dashboard&utm_campaign=go_premium" target="_blank">
527 <span style="color: #ff7742; font-weight: bold;">' .
528 __( 'Upgrade to Pro', 'wp-megamenu' ) .
529 '</span>
530 </a>';
531 }
532
533 $actions['settings'] = '<a href="admin.php?page=tutor_settings">' . __( 'Settings', 'tutor' ) . '</a>';
534
535 return $actions;
536 }
537
538 /**
539 * Add plugin meta data in WP plugins list page
540 *
541 * @param array $plugin_meta plugin meta data.
542 * @param string $plugin_file plugin file.
543 * @return array
544 * @since 1.0.0
545 */
546 public function plugin_row_meta( $plugin_meta, $plugin_file ) {
547
548 if ( tutor()->basename === $plugin_file ) {
549 $plugin_meta[] = sprintf(
550 '<a href="%s">%s</a>',
551 esc_url( 'https://docs.themeum.com/tutor-lms/?utm_source=tutor&utm_medium=plugins_installation_list&utm_campaign=plugin_docs_link' ),
552 __( '<strong style="color: #03bd24">Documentation</strong>', 'tutor' )
553 );
554 $plugin_meta[] = sprintf(
555 '<a href="%s">%s</a>',
556 esc_url( 'https://www.themeum.com/contact-us/?utm_source=tutor&utm_medium=plugins_installation_list&utm_campaign=plugin_support_link' ),
557 __( '<strong style="color: #03bd24">Get Support</strong>', 'tutor' )
558 );
559 }
560
561 return $plugin_meta;
562 }
563
564 /**
565 * Add footer text only on tutor pages
566 *
567 * @param string $footer_text footer text.
568 * @return string
569 * @since 1.0.0
570 */
571 public function admin_footer_text( $footer_text ) {
572 $current_screen = get_current_screen();
573
574 /**
575 * We are making sure that this message will be only on Tutor Admin page
576 */
577 if ( apply_filters( 'tutor_display_admin_footer_text', ( tutor_utils()->array_get( 'parent_base', $current_screen ) === 'tutor' ) ) ) {
578 $footer_text = sprintf(
579 /* translators: %s: plugin name */
580 __( 'If you like %1$s please leave us a %2$s rating. A huge thanks in advance!', 'tutor' ),
581 sprintf( '<strong>%s</strong>', esc_html__( 'Tutor LMS', 'tutor' ) ),
582 '<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>'
583 );
584 }
585
586 return $footer_text;
587 }
588
589 /**
590 * Register course widget
591 *
592 * @return void
593 * @since 1.0.0
594 */
595 public function register_course_widget() {
596 register_widget( 'Tutor\Course_Widget' );
597 }
598
599 /**
600 * Tutor Course List
601 *
602 * @return void
603 * @since v2.0.0
604 */
605 public function tutor_course_list() {
606 include tutor()->path . 'views/pages/course-list.php';
607 }
608
609 /**
610 * Show welcome page
611 *
612 * @return void
613 * @since 1.0.0
614 */
615 public function welcome_page() {
616 Tutor_Setup::mark_as_visited();
617 include tutor()->path . 'views/pages/welcome.php';
618 exit;
619 }
620 }
621