PluginProbe
FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel / v1.3
FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel vv1.3
1.7.1 1.7.0 1.6.0 1.5.2 trunk 0.1 0.2.0 0.2.1 0.3 0.3.1 0.3.2 0.3.3 0.3.4 0.4 0.4.1 0.4.2 0.4.3 1.0 1.1 1.2 1.3.1 1.4.0 1.4.1 1.5.0 1.5.1 All 26 releases
← All changes | includes/Admin.php +63 -9 0.3v1.3 View file →
@@ -6,9 +6,9 @@
6 6
7 7 /**
8 8 * Admin page slug.
9 9 */
10 - const PAGE_SLUG = 'flywp';
10 + public const PAGE_SLUG = 'flywp';
11 11
12 12 /**
13 13 * Screen name.
14 14 *
@@ -13,11 +13,12 @@
13 13 * Screen name.
14 14 *
15 15 * @var string
16 16 */
17 - const SCREEN_NAME = 'tools_page_flywp';
17 + public const SCREEN_NAME = 'dashboard_page_flywp';
18 18
19 - public $fastcgi = null;
19 + public $fastcgi = null;
20 + public $litespeed = null;
20 21
21 22 /**
22 23 * Admin constructor.
23 24 */
@@ -23,13 +24,16 @@
23 24 */
24 25 public function __construct() {
25 26 add_action( 'admin_menu', [ $this, 'register_admin_page' ] );
26 27
27 - $this->fastcgi = new Admin\Fastcgi_Cache();
28 + $this->fastcgi = new Admin\Fastcgi_Cache();
29 + $this->litespeed = new Admin\Litespeed();
28 30
29 31 new Admin\Adminbar();
30 32 new Admin\Opcache();
31 33 new Admin\Plugins();
34 + new Admin\Email();
35 + new Admin\Optimizations();
32 36 }
33 37
34 38 /**
35 39 * Register admin page.
@@ -34,10 +38,9 @@
34 38 /**
35 39 * Register admin page.
36 40 */
37 41 public function register_admin_page() {
38 - $hook = add_submenu_page(
39 - 'tools.php',
42 + $hook = add_dashboard_page(
40 43 __( 'FlyWP', 'flywp' ),
41 44 __( 'FlyWP', 'flywp' ),
42 45 'manage_options',
43 46 self::PAGE_SLUG,
@@ -54,9 +57,9 @@
54 57 *
55 58 * @return string
56 59 */
57 60 public function page_url() {
58 - return admin_url( 'tools.php?page=' . self::PAGE_SLUG );
61 + return admin_url( 'index.php?page=' . self::PAGE_SLUG );
59 62 }
60 63
61 64 /**
62 65 * Add query args to removable query args.
@@ -85,10 +88,9 @@
85 88 */
86 89 public function enqueue_js() {
87 90 $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
88 91
89 - wp_enqueue_script( 'flywp-chart', FLYWP_PLUGIN_URL . '/assets/js/chart.min.js', [], FLYWP_VERSION, true );
90 - wp_enqueue_script( 'flywp-admin-js', FLYWP_PLUGIN_URL . '/assets/js/admin' . $min . '.js', [ 'jquery', 'flywp-chart' ], FLYWP_VERSION, true );
92 + wp_enqueue_script( 'flywp-admin-js', FLYWP_PLUGIN_URL . '/assets/js/admin' . $min . '.js', [ 'jquery' ], FLYWP_VERSION, true );
91 93 }
92 94
93 95 /**
94 96 * Render admin page.
@@ -93,7 +95,59 @@
93 95 /**
94 96 * Render admin page.
95 97 */
96 98 public function render_admin_page() {
99 + $tabs = [
100 + 'cache' => __( 'Caching', 'flywp' ),
101 + 'email' => __( 'Email', 'flywp' ),
102 + 'optimizations' => __( 'Optimizations', 'flywp' ),
103 + ];
104 +
105 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended
106 + $active_tab = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $tabs ) ? $_GET['tab'] : 'cache';
107 + $site_info = $this->fetch_site_info();
108 + $app_site_url = $this->get_site_url( $site_info );
109 +
97 110 include FLYWP_PLUGIN_DIR . '/views/admin.php';
111 + }
112 +
113 + /**
114 + * Fetch site info.
115 + *
116 + * @return array|false
117 + */
118 + private function fetch_site_info() {
119 + $transient_key = 'flywp_site_info';
120 + $site_info = get_transient( $transient_key );
121 +
122 + if ( false === $site_info ) {
123 + $site_info = flywp()->flyapi->site_info();
124 +
125 + if ( isset( $site_info['error'] ) ) {
126 + return false;
127 + }
128 +
129 + set_transient( $transient_key, $site_info, DAY_IN_SECONDS );
130 + }
131 +
132 + return $site_info;
133 + }
134 +
135 + /**
136 + * Get site URL.
137 + *
138 + * @param array|false $info
139 + *
140 + * @return string
141 + */
142 + private function get_site_url( $info ) {
143 + if ( false === $info ) {
144 + return 'https://app.flywp.com';
145 + }
146 +
147 + return sprintf(
148 + 'https://app.flywp.com/servers/%d/sites/%d',
149 + $info['server_id'],
150 + $info['id']
151 + );
98 152 }
99 153 }