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