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

flywp.php in FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel 1.4.0, at flywp.php

167 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: FlyWP
4 * Plugin URI: https://flywp.com
5 * Description: Helper plugin for FlyWP
6 * Version: 1.4.0
7 * Author: FlyWP
8 * Author URI: https://flywp.com/?utm_source=wporg&utm_medium=banner&utm_campaign=author-uri
9 * License: GPL2
10 */
11
12 // Exit if accessed directly.
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 require __DIR__ . '/vendor/autoload.php';
18
19 use WeDevs\WpUtils\ContainerTrait;
20 use WeDevs\WpUtils\HookTrait;
21 use WeDevs\WpUtils\SingletonTrait;
22
23 /**
24 * Main FlyWP Class.
25 *
26 * @var admin FlyWP\Admin
27 * @var rest FlyWP\Api
28 * @var fastcgi FlyWP\Fastcgi_Cache
29 * @var router FlyWP\Router
30 *
31 * @class FlyWP
32 */
33 final class FlyWP_Plugin {
34
35 use SingletonTrait;
36 use ContainerTrait;
37 use HookTrait;
38
39 /**
40 * Plugin version.
41 *
42 * @var string
43 */
44 public $version = '1.4.0';
45
46 /**
47 * Plugin Constructor.
48 *
49 * @return void
50 */
51 private function __construct() {
52 $this->define_constants();
53
54 $this->add_action( 'plugins_loaded', 'init_plugin' );
55 register_activation_hook( __FILE__, [ $this, 'activate' ] );
56 register_deactivation_hook( __FILE__, [ $this, 'deactivate' ] );
57 }
58
59 /**
60 * Define plugin constants.
61 *
62 * @return void
63 */
64 private function define_constants() {
65 define( 'FLYWP_VERSION', $this->version );
66 define( 'FLYWP_PLUGIN_FILE', __FILE__ );
67 define( 'FLYWP_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
68 define( 'FLYWP_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
69 define( 'FLYWP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
70
71 if ( ! defined( 'FLYWP_API_KEY' ) ) {
72 define( 'FLYWP_API_KEY', '' );
73 }
74 }
75
76 /**
77 * Plugin activation hook.
78 *
79 * @return void
80 */
81 public function activate() {
82 $router = new FlyWP\Router();
83 $router->register_routes();
84
85 flush_rewrite_rules( false );
86 }
87
88 /**
89 * Plugin activation hook.
90 *
91 * @return void
92 */
93 public function deactivate() {
94 ( new FlyWP\Api\UpdatesData() )->deactivate();
95 }
96
97 /**
98 * Initialize plugin.
99 *
100 * @return void
101 */
102 public function init_plugin() {
103 if ( ! $this->has_key() ) {
104 $this->add_action( 'admin_notices', 'admin_notice' );
105
106 return;
107 }
108
109 if ( is_admin() ) {
110 $this->admin = new FlyWP\Admin();
111 } else {
112 $this->frontend = new FlyWP\Frontend();
113 }
114
115 $this->router = new FlyWP\Router();
116 $this->rest = new FlyWP\Api();
117 $this->fastcgi = new FlyWP\Fastcgi_Cache();
118 $this->opcache = new FlyWP\Opcache();
119 $this->flyapi = new FlyWP\FlyApi();
120 $this->email = new FlyWP\Email();
121 $this->optimize = new FlyWP\Optimizations();
122 $this->litespeed = new FlyWP\Litespeed();
123 $this->updates_data = new FlyWP\Api\UpdatesData();
124 }
125
126 /**
127 * Show admin notice if API key is not set.
128 *
129 * @return void
130 */
131 public function admin_notice() {
132 $message = __( 'Missing FlyWP API key, plugin requires an API key.', 'flywp' );
133
134 echo '<div class="notice notice-error"><p>' . esc_html( $message ) . '</p></div>';
135 }
136
137 /**
138 * Check if API key is set.
139 *
140 * @return bool
141 */
142 public function has_key() {
143 return FLYWP_API_KEY !== '';
144 }
145
146 /**
147 * Get API key.
148 *
149 * @return string
150 */
151 public function get_key() {
152 return FLYWP_API_KEY;
153 }
154 }
155
156 /**
157 * Returns the main instance of FlyWP to prevent the need to use globals.
158 *
159 * @return FlyWP_Plugin
160 */
161 function flywp() {
162 return FlyWP_Plugin::instance();
163 }
164
165 // take off
166 flywp();
167