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