PluginProbe
FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel / 1.1
FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel v1.1
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
flywp / includes / Admin.php

Admin.php in FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel 1.1, at includes/Admin.php

149 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FlyWP;
4
5 class Admin {
6
7 /**
8 * Admin page slug.
9 */
10 const PAGE_SLUG = 'flywp';
11
12 /**
13 * Screen name.
14 *
15 * @var string
16 */
17 const SCREEN_NAME = 'dashboard_page_flywp';
18
19 public $fastcgi = null;
20
21 /**
22 * Admin constructor.
23 */
24 public function __construct() {
25 add_action( 'admin_menu', [ $this, 'register_admin_page' ] );
26
27 $this->fastcgi = new Admin\Fastcgi_Cache();
28
29 new Admin\Adminbar();
30 new Admin\Opcache();
31 new Admin\Plugins();
32 new Admin\Email();
33 }
34
35 /**
36 * Register admin page.
37 */
38 public function register_admin_page() {
39 $hook = add_dashboard_page(
40 __( 'FlyWP', 'flywp' ),
41 __( 'FlyWP', 'flywp' ),
42 'manage_options',
43 self::PAGE_SLUG,
44 [$this, 'render_admin_page']
45 );
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'] );
50 }
51
52 /**
53 * Get admin page url.
54 *
55 * @return string
56 */
57 public function page_url() {
58 return admin_url( 'index.php?page=' . self::PAGE_SLUG );
59 }
60
61 /**
62 * Add query args to removable query args.
63 *
64 * @param array $args
65 *
66 * @return array
67 */
68 public function removable_query_args( $args ) {
69 $args[] = 'fly-notice';
70
71 return $args;
72 }
73
74 /**
75 * Enqueue admin styles.
76 */
77 public function enqueue_styles() {
78 $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
79
80 wp_enqueue_style( 'flywp-admin-styles', FLYWP_PLUGIN_URL . '/assets/css/app' . $min . '.css', [], FLYWP_VERSION );
81 }
82
83 /**
84 * Enqueue admin scripts.
85 */
86 public function enqueue_js() {
87 $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
88
89 wp_enqueue_script( 'flywp-admin-js', FLYWP_PLUGIN_URL . '/assets/js/admin' . $min . '.js', ['jquery'], FLYWP_VERSION, true );
90 }
91
92 /**
93 * Render admin page.
94 */
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
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 );
147 }
148 }
149