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
Tools.php
95 lines
| 1 | <?php |
| 2 | |
| 3 | namespace TUTOR; |
| 4 | |
| 5 | if ( ! defined( 'ABSPATH' ) ) { |
| 6 | exit; |
| 7 | } |
| 8 | |
| 9 | use TUTOR\Input; |
| 10 | |
| 11 | class Tools { |
| 12 | |
| 13 | public function __construct() { |
| 14 | add_action( 'tutor_action_regenerate_tutor_pages', array( $this, 'regenerate_tutor_pages' ) ); |
| 15 | |
| 16 | add_action( 'tutor_option_save_after', array( $this, 'tutor_option_save_after' ) ); |
| 17 | add_action( 'init', array( $this, 'check_if_maintenance' ) ); |
| 18 | |
| 19 | add_action( 'admin_init', array( $this, 'redirect_to_wizard_page' ) ); |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Re-Generate Tutor Missing Pages |
| 24 | * |
| 25 | * @since v.1.4.3 |
| 26 | */ |
| 27 | public function regenerate_tutor_pages() { |
| 28 | tutor_utils()->checking_nonce(); |
| 29 | |
| 30 | $tutor_pages = tutor_utils()->tutor_pages(); |
| 31 | |
| 32 | foreach ( $tutor_pages as $page ) { |
| 33 | $visible = tutor_utils()->array_get( 'page_visible', $page ); |
| 34 | $page_title = tutor_utils()->array_get( 'page_name', $page ); |
| 35 | $option_key = tutor_utils()->array_get( 'option_key', $page ); |
| 36 | $page_id = tutor_utils()->array_get( 'page_id', $page ); |
| 37 | |
| 38 | $page_content = ''; |
| 39 | if ( $option_key === 'tutor_login_page' ) { |
| 40 | $page_content = '[tutor_login]'; |
| 41 | } |
| 42 | |
| 43 | if ( ! $visible ) { |
| 44 | $page_arg = array( |
| 45 | 'ID' => $page_id, |
| 46 | 'post_title' => $page_title, |
| 47 | 'post_content' => $page_content, |
| 48 | 'post_type' => 'page', |
| 49 | 'post_status' => 'publish', |
| 50 | ); |
| 51 | $page_id = wp_insert_post( $page_arg ); |
| 52 | update_tutor_option( $option_key, $page_id ); |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | public function tutor_option_save_after() { |
| 58 | $maintenance_mode = (bool) get_tutor_option( 'enable_tutor_maintenance_mode' ); |
| 59 | if ( $maintenance_mode ) { |
| 60 | tutor_maintenance_mode( true ); |
| 61 | } else { |
| 62 | tutor_maintenance_mode(); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | public function check_if_maintenance() { |
| 67 | if ( ! is_admin() && ! $this->is_wplogin() ) { |
| 68 | $maintenance_mode = (bool) get_tutor_option( 'enable_tutor_maintenance_mode' ); |
| 69 | if ( false === $maintenance_mode || current_user_can( 'administrator' ) ) { |
| 70 | return; |
| 71 | } |
| 72 | header( 'Retry-After: 600' ); |
| 73 | include tutor()->path . 'views/maintenance.php'; |
| 74 | die(); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | public function is_wplogin() { |
| 79 | $ABSPATH_MY = str_replace( array( '\\', '/' ), DIRECTORY_SEPARATOR, ABSPATH ); |
| 80 | return ( ( in_array( $ABSPATH_MY . 'wp-login.php', get_included_files() ) || in_array( $ABSPATH_MY . 'wp-register.php', get_included_files() ) ) || ( isset( $_GLOBALS['pagenow'] ) && $GLOBALS['pagenow'] === 'wp-login.php' ) || $_SERVER['PHP_SELF'] == '/wp-login.php' ); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Redirect to setup wizard page if any one click on the menu from tools page |
| 85 | * |
| 86 | * @since v.1.5.7 |
| 87 | */ |
| 88 | public function redirect_to_wizard_page() { |
| 89 | if ( Input::get( 'page' ) === 'tutor-tools' && Input::get( 'sub_page' ) === 'tutor-setup' ) { |
| 90 | exit( wp_redirect( admin_url( 'admin.php?page=tutor-setup' ) ) ); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | } |
| 95 |