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 | flywp.php +41 -105 trunk0.1 View file →
@@ -2,11 +2,10 @@
2 2 /**
3 3 * Plugin Name: FlyWP
4 4 * Plugin URI: https://flywp.com
5 5 * Description: Helper plugin for FlyWP
6 - * Version: 1.7.1
6 + * Version: 0.1
7 7 * Author: FlyWP
8 - * Author URI: https://flywp.com/?utm_source=wporg&utm_medium=banner&utm_campaign=author-uri
9 8 * License: GPL2
10 9 */
11 10
12 11 // Exit if accessed directly.
@@ -15,124 +14,62 @@
15 14 }
16 15
17 16 require __DIR__ . '/vendor/autoload.php';
18 17
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 18 final class FlyWP_Plugin {
34 19
35 - use SingletonTrait;
36 - use ContainerTrait;
37 - use HookTrait;
38 -
39 20 /**
40 21 * Plugin version.
41 22 *
42 23 * @var string
43 24 */
44 - public $version = '1.7.1';
25 + private $version = '1.0.0';
45 26
46 27 /**
47 - * Plugin Constructor.
28 + * The single instance of the class.
48 29 *
49 - * @return void
30 + * @var FlyWP
50 31 */
51 - private function __construct() {
52 - $this->define_constants();
32 + private static $instance = null;
53 33
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 34 /**
60 - * Define plugin constants.
35 + * Plugin Constructor.
61 36 *
62 37 * @return void
63 38 */
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__ ) );
39 + private function __construct() {
40 + $this->define_constants();
70 41
71 - if ( ! defined( 'FLYWP_API_KEY' ) ) {
72 - define( 'FLYWP_API_KEY', '' );
73 - }
74 -
75 - if ( ! defined( 'FLYWP_LOGIN_PUBLIC_KEY' ) ) {
76 - define( 'FLYWP_LOGIN_PUBLIC_KEY', '' );
77 - }
42 + add_action( 'plugins_loaded', [ $this, 'init_plugin' ] );
78 43 }
79 44
80 45 /**
81 - * Plugin activation hook.
46 + * Main FlyWP Instance.
82 47 *
83 - * @return void
84 - */
85 - public function activate() {
86 - $router = new FlyWP\Router();
87 - $router->register_routes();
88 -
89 - flush_rewrite_rules( false );
90 - }
91 -
92 - /**
93 - * Plugin deactivation hook.
48 + * Ensures only one instance of FlyWP is loaded or can be loaded.
94 49 *
95 - * @return void
50 + * @return flyWP - Main instance
96 51 */
97 - public function deactivate() {
98 - $timestamp = wp_next_scheduled( FlyWP\Api\UpdatesData::CRON_HOOK );
99 - if ( $timestamp ) {
100 - wp_unschedule_event( $timestamp, FlyWP\Api\UpdatesData::CRON_HOOK );
52 + public static function instance() {
53 + if ( null === self::$instance ) {
54 + self::$instance = new self();
101 55 }
56 +
57 + return self::$instance;
102 58 }
103 59
104 - /**
105 - * Initialize plugin.
106 - *
107 - * @return void
108 - */
109 60 public function init_plugin() {
110 - // Loaded ahead of the API-key gate below, as it does not use the API key. It answers
111 - // one POST path and does nothing on any other request.
112 - new FlyWP\Frontend\MagicLogin();
61 + if ( ! $this->has_api_key() ) {
62 + add_action( 'admin_notices', [ $this, 'admin_notice' ] );
113 63
114 - if ( ! $this->has_key() ) {
115 - $this->add_action( 'admin_notices', 'admin_notice' );
116 -
117 64 return;
118 65 }
119 66
120 67 if ( is_admin() ) {
121 - $this->admin = new FlyWP\Admin();
68 + new FlyWP\Admin();
122 69 } else {
123 - $this->frontend = new FlyWP\Frontend();
70 + new FlyWP\Frontend();
124 71 }
125 -
126 - $this->router = new FlyWP\Router();
127 - $this->rest = new FlyWP\Api();
128 - $this->fastcgi = new FlyWP\Fastcgi_Cache();
129 - $this->opcache = new FlyWP\Opcache();
130 - $this->flyapi = new FlyWP\FlyApi();
131 - $this->email = new FlyWP\Email();
132 - $this->optimize = new FlyWP\Optimizations();
133 - $this->litespeed = new FlyWP\Litespeed();
134 - $this->updates_data = new FlyWP\Api\UpdatesData();
135 72 }
136 73
137 74 /**
138 75 * Show admin notice if API key is not set.
@@ -145,13 +82,30 @@
145 82 echo '<div class="notice notice-error"><p>' . esc_html( $message ) . '</p></div>';
146 83 }
147 84
148 85 /**
86 + * Define plugin constants.
87 + *
88 + * @return void
89 + */
90 + private function define_constants() {
91 + define( 'FLYWP_VERSION', $this->version );
92 + define( 'FLYWP_PLUGIN_FILE', __FILE__ );
93 + define( 'FLYWP_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
94 + define( 'FLYWP_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
95 + define( 'FLYWP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
96 +
97 + if ( ! defined( 'FLYWP_API_KEY' ) ) {
98 + define( 'FLYWP_API_KEY', '' );
99 + }
100 + }
101 +
102 + /**
149 103 * Check if API key is set.
150 104 *
151 105 * @return bool
152 106 */
153 - public function has_key() {
107 + public function has_api_key() {
154 108 return FLYWP_API_KEY !== '';
155 109 }
156 110
157 111 /**
@@ -158,35 +112,17 @@
158 112 * Get API key.
159 113 *
160 114 * @return string
161 115 */
162 - public function get_key() {
116 + public function get_api_key() {
163 117 return FLYWP_API_KEY;
164 118 }
165 -
166 - /**
167 - * Public key used to verify magic-login tokens.
168 - *
169 - * Set as a constant on classic WordPress. On Bedrock it may only be present in the
170 - * environment, so fall back to `getenv()`.
171 - *
172 - * @return string
173 - */
174 - public function get_login_public_key() {
175 - if ( FLYWP_LOGIN_PUBLIC_KEY !== '' ) {
176 - return FLYWP_LOGIN_PUBLIC_KEY;
177 - }
178 -
179 - $from_env = getenv( 'FLYWP_LOGIN_PUBLIC_KEY' );
180 -
181 - return $from_env === false ? '' : $from_env;
182 - }
183 119 }
184 120
185 121 /**
186 122 * Returns the main instance of FlyWP to prevent the need to use globals.
187 123 *
188 - * @return FlyWP_Plugin
124 + * @return FlyWP
189 125 */
190 126 function flywp() {
191 127 return FlyWP_Plugin::instance();
192 128 }