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