PluginProbe
FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel / 1.0
FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel v1.0
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 +59 -10 0.3.11.0 View file →
@@ -13,9 +13,9 @@
13 13 * Screen name.
14 14 *
15 15 * @var string
16 16 */
17 - const SCREEN_NAME = 'tools_page_flywp';
17 + const SCREEN_NAME = 'dashboard_page_flywp';
18 18
19 19 public $fastcgi = null;
20 20
21 21 /**
@@ -28,8 +28,9 @@
28 28
29 29 new Admin\Adminbar();
30 30 new Admin\Opcache();
31 31 new Admin\Plugins();
32 + new Admin\Email();
32 33 }
33 34
34 35 /**
35 36 * Register admin page.
@@ -34,20 +35,19 @@
34 35 /**
35 36 * Register admin page.
36 37 */
37 38 public function register_admin_page() {
38 - $hook = add_submenu_page(
39 - 'tools.php',
39 + $hook = add_dashboard_page(
40 40 __( 'FlyWP', 'flywp' ),
41 41 __( 'FlyWP', 'flywp' ),
42 42 'manage_options',
43 43 self::PAGE_SLUG,
44 - [ $this, 'render_admin_page' ]
44 + [$this, 'render_admin_page']
45 45 );
46 46
47 - add_action( "admin_print_styles-{$hook}", [ $this, 'enqueue_styles' ] );
48 - add_action( "admin_print_scripts-{$hook}", [ $this, 'enqueue_js' ] );
49 - add_filter( 'removable_query_args', [ $this, 'removable_query_args' ] );
47 + add_action( "admin_print_styles-{$hook}", [$this, 'enqueue_styles'] );
48 + add_action( "admin_print_scripts-{$hook}", [$this, 'enqueue_js'] );
49 + add_filter( 'removable_query_args', [$this, 'removable_query_args'] );
50 50 }
51 51
52 52 /**
53 53 * Get admin page url.
@@ -54,9 +54,9 @@
54 54 *
55 55 * @return string
56 56 */
57 57 public function page_url() {
58 - return admin_url( 'tools.php?page=' . self::PAGE_SLUG );
58 + return admin_url( 'index.php?page=' . self::PAGE_SLUG );
59 59 }
60 60
61 61 /**
62 62 * Add query args to removable query args.
@@ -85,10 +85,9 @@
85 85 */
86 86 public function enqueue_js() {
87 87 $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
88 88
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 );
89 + wp_enqueue_script( 'flywp-admin-js', FLYWP_PLUGIN_URL . '/assets/js/admin' . $min . '.js', ['jquery'], FLYWP_VERSION, true );
91 90 }
92 91
93 92 /**
94 93 * Render admin page.
@@ -93,7 +92,57 @@
93 92 /**
94 93 * Render admin page.
95 94 */
96 95 public function render_admin_page() {
96 + $tabs = [
97 + 'cache' => __( 'Caching', 'flywp' ),
98 + 'email' => __( 'Email', 'flywp' ),
99 + ];
100 +
101 + $active_tab = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $tabs ) ? $_GET['tab'] : 'cache';
102 + $site_info = $this->fetch_site_info();
103 + $app_site_url = $this->get_site_url( $site_info );
104 +
97 105 include FLYWP_PLUGIN_DIR . '/views/admin.php';
106 + }
107 +
108 + /**
109 + * Fetch site info.
110 + *
111 + * @return array|false
112 + */
113 + private function fetch_site_info() {
114 + $transient_key = 'flywp_site_info';
115 + $site_info = get_transient( $transient_key );
116 +
117 + if ( false === $site_info ) {
118 + $site_info = flywp()->flyapi->site_info();
119 +
120 + if ( isset( $site_info['error'] ) ) {
121 + return false;
122 + }
123 +
124 + set_transient( $transient_key, $site_info, DAY_IN_SECONDS );
125 + }
126 +
127 + return $site_info;
128 + }
129 +
130 + /**
131 + * Get site URL.
132 + *
133 + * @param array|false $info
134 + *
135 + * @return string
136 + */
137 + private function get_site_url( $info ) {
138 + if ( false === $info ) {
139 + return 'https://app.flywp.com';
140 + }
141 +
142 + return sprintf(
143 + 'https://app.flywp.com/servers/%d/sites/%d',
144 + $info['server_id'],
145 + $info['id']
146 + );
98 147 }
99 148 }