PluginProbe
FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel / 0.1
FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel v0.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
← All changes | includes/Admin.php +1 -141 1.20.1 View file →
@@ -3,148 +3,8 @@
3 3 namespace FlyWP;
4 4
5 5 class Admin {
6 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 7 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 - new Admin\Optimizations();
34 - }
35 -
36 - /**
37 - * Register admin page.
38 - */
39 - public function register_admin_page() {
40 - $hook = add_dashboard_page(
41 - __( 'FlyWP', 'flywp' ),
42 - __( 'FlyWP', 'flywp' ),
43 - 'manage_options',
44 - self::PAGE_SLUG,
45 - [ $this, 'render_admin_page' ]
46 - );
47 -
48 - add_action( "admin_print_styles-{$hook}", [ $this, 'enqueue_styles' ] );
49 - add_action( "admin_print_scripts-{$hook}", [ $this, 'enqueue_js' ] );
50 - add_filter( 'removable_query_args', [ $this, 'removable_query_args' ] );
51 - }
52 -
53 - /**
54 - * Get admin page url.
55 - *
56 - * @return string
57 - */
58 - public function page_url() {
59 - return admin_url( 'index.php?page=' . self::PAGE_SLUG );
60 - }
61 -
62 - /**
63 - * Add query args to removable query args.
64 - *
65 - * @param array $args
66 - *
67 - * @return array
68 - */
69 - public function removable_query_args( $args ) {
70 - $args[] = 'fly-notice';
71 -
72 - return $args;
73 - }
74 -
75 - /**
76 - * Enqueue admin styles.
77 - */
78 - public function enqueue_styles() {
79 - $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
80 -
81 - wp_enqueue_style( 'flywp-admin-styles', FLYWP_PLUGIN_URL . '/assets/css/app' . $min . '.css', [], FLYWP_VERSION );
82 - }
83 -
84 - /**
85 - * Enqueue admin scripts.
86 - */
87 - public function enqueue_js() {
88 - $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
89 -
90 - wp_enqueue_script( 'flywp-admin-js', FLYWP_PLUGIN_URL . '/assets/js/admin' . $min . '.js', [ 'jquery' ], FLYWP_VERSION, true );
91 - }
92 -
93 - /**
94 - * Render admin page.
95 - */
96 - public function render_admin_page() {
97 - $tabs = [
98 - 'cache' => __( 'Caching', 'flywp' ),
99 - 'email' => __( 'Email', 'flywp' ),
100 - 'optimizations' => __( 'Optimizations', 'flywp' ),
101 - ];
102 -
103 - $active_tab = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $tabs ) ? $_GET['tab'] : 'cache';
104 - $site_info = $this->fetch_site_info();
105 - $app_site_url = $this->get_site_url( $site_info );
106 -
107 - include FLYWP_PLUGIN_DIR . '/views/admin.php';
108 - }
109 -
110 - /**
111 - * Fetch site info.
112 - *
113 - * @return array|false
114 - */
115 - private function fetch_site_info() {
116 - $transient_key = 'flywp_site_info';
117 - $site_info = get_transient( $transient_key );
118 -
119 - if ( false === $site_info ) {
120 - $site_info = flywp()->flyapi->site_info();
121 -
122 - if ( isset( $site_info['error'] ) ) {
123 - return false;
124 - }
125 -
126 - set_transient( $transient_key, $site_info, DAY_IN_SECONDS );
127 - }
128 -
129 - return $site_info;
130 - }
131 -
132 - /**
133 - * Get site URL.
134 - *
135 - * @param array|false $info
136 - *
137 - * @return string
138 - */
139 - private function get_site_url( $info ) {
140 - if ( false === $info ) {
141 - return 'https://app.flywp.com';
142 - }
143 -
144 - return sprintf(
145 - 'https://app.flywp.com/servers/%d/sites/%d',
146 - $info['server_id'],
147 - $info['id']
148 - );
8 + // code
149 9 }
150 10 }