PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.9
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.9
4.4.9 4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 All 140 releases
learnpress / inc / TemplateHooks / Admin / AdminToolsPage.php

AdminToolsPage.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.4.9, at inc/TemplateHooks/Admin/AdminToolsPage.php

123 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace LearnPress\TemplateHooks\Admin;
4
5 use LearnPress\Helpers\Singleton;
6 use LP_Cache;
7 use LP_Helper;
8
9 defined( 'ABSPATH' ) || exit();
10
11 /**
12 * Admin Tools page renderer.
13 *
14 * @since 4.2.8
15 */
16 class AdminToolsPage {
17 use Singleton;
18
19 /**
20 * Singleton initialization hook.
21 *
22 * @return void
23 */
24 public function init(): void {}
25
26 /**
27 * Tools tabs with their labels.
28 *
29 * @return array
30 */
31 private static function get_tabs(): array {
32 return apply_filters(
33 'learn-press/admin/tools-tabs',
34 array(
35 'course' => __( 'Course Data', 'learnpress' ),
36 'assign_course' => __( 'Assign/Unassigned Course', 'learnpress' ),
37 'database' => __( 'Database', 'learnpress' ),
38 'template' => __( 'Templates', 'learnpress' ),
39 'cache' => __( 'Cache', 'learnpress' ),
40 )
41 );
42 }
43
44 /**
45 * Map of tool tabs to view paths.
46 *
47 * @return array
48 */
49 private static function get_tab_views(): array {
50 return apply_filters(
51 'learn-press/admin/tools-tab-views',
52 array(
53 'course' => 'tools/html-course',
54 'database' => 'tools/html-database',
55 'template' => 'tools/html-template',
56 )
57 );
58 }
59
60 /**
61 * Render the LearnPress Tools page.
62 *
63 * @return void
64 */
65 public function html_page() {
66 $tabs = self::get_tabs();
67 $tab_views = self::get_tab_views();
68 $tab = isset( $_REQUEST['tab'] ) ? LP_Helper::sanitize_params_submitted( $_REQUEST['tab'] ) : '';
69 $tab = array_key_exists( $tab, $tabs ) ? $tab : ( array_key_first( $tabs ) ?? '' );
70
71 ob_start();
72 ?>
73 <div class="lp-admin-tab-content">
74 <?php
75 if ( isset( $tab_views[ $tab ] ) ) {
76 learn_press_admin_view( $tab_views[ $tab ] );
77 } else {
78 $this->render_custom_tab( $tab );
79 }
80 ?>
81 </div>
82 <?php
83 $content = ob_get_clean();
84
85 echo AdminTemplate::html_on_wp_admin_screen(
86 array(
87 'tabs' => $tabs,
88 'content' => $content,
89 'title' => __( 'LearnPress Tools', 'learnpress' ),
90 'id' => 'learn-press-tools',
91 )
92 );
93 }
94
95 /**
96 * Render tabs that do not have a dedicated view file.
97 *
98 * @param string $tab Active tab slug.
99 *
100 * @return void
101 */
102 private function render_custom_tab( string $tab ) {
103 switch ( $tab ) {
104 case 'assign_course':
105 learn_press_admin_view( 'tools/course/html-assign-course' );
106 learn_press_admin_view( 'tools/course/html-unassign-course' );
107 break;
108 case 'cache':
109 $lp_cache = new LP_Cache( true );
110 $lp_cache->clear_all();
111
112 echo sprintf(
113 '<form action="" method="post"><button class="button button-primary" type="submit">%s</button></form>',
114 esc_html__( 'Clear all cache', 'learnpress' )
115 );
116 break;
117 default:
118 do_action( 'learn-press/admin/tools-tab-content', $tab );
119 break;
120 }
121 }
122 }
123