PluginProbe
FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel / v1.3
FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel vv1.3
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 +66 -42 0.1v1.3 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.3
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,102 @@
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.3';
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 + }
57 +
34 58 /**
35 - * Plugin Constructor.
59 + * Define plugin constants.
36 60 *
37 61 * @return void
38 62 */
39 - private function __construct() {
40 - $this->define_constants();
63 + private function define_constants() {
64 + define( 'FLYWP_VERSION', $this->version );
65 + define( 'FLYWP_PLUGIN_FILE', __FILE__ );
66 + define( 'FLYWP_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
67 + define( 'FLYWP_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
68 + define( 'FLYWP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
41 69
42 - add_action( 'plugins_loaded', [ $this, 'init_plugin' ] );
70 + if ( ! defined( 'FLYWP_API_KEY' ) ) {
71 + define( 'FLYWP_API_KEY', '' );
72 + }
43 73 }
44 74
45 75 /**
46 - * Main FlyWP Instance.
76 + * Plugin activation hook.
47 77 *
48 - * Ensures only one instance of FlyWP is loaded or can be loaded.
49 - *
50 - * @return flyWP - Main instance
78 + * @return void
51 79 */
52 - public static function instance() {
53 - if ( null === self::$instance ) {
54 - self::$instance = new self();
55 - }
80 + public function activate() {
81 + $router = new FlyWP\Router();
82 + $router->register_routes();
56 83
57 - return self::$instance;
84 + flush_rewrite_rules( false );
58 85 }
59 86
87 + /**
88 + * Initialize plugin.
89 + *
90 + * @return void
91 + */
60 92 public function init_plugin() {
61 - if ( ! $this->has_api_key() ) {
62 - add_action( 'admin_notices', [ $this, 'admin_notice' ] );
93 + if ( ! $this->has_key() ) {
94 + $this->add_action( 'admin_notices', 'admin_notice' );
63 95
64 96 return;
65 97 }
66 98
67 99 if ( is_admin() ) {
68 - new FlyWP\Admin();
100 + $this->admin = new FlyWP\Admin();
69 101 } else {
70 - new FlyWP\Frontend();
102 + $this->frontend = new FlyWP\Frontend();
71 103 }
104 +
105 + $this->router = new FlyWP\Router();
106 + $this->rest = new FlyWP\Api();
107 + $this->fastcgi = new FlyWP\Fastcgi_Cache();
108 + $this->opcache = new FlyWP\Opcache();
109 + $this->flyapi = new FlyWP\FlyApi();
110 + $this->email = new FlyWP\Email();
111 + $this->optimize = new FlyWP\Optimizations();
112 + $this->litespeed = new FlyWP\Litespeed();
72 113 }
73 114
74 115 /**
75 116 * Show admin notice if API key is not set.
@@ -82,30 +123,13 @@
82 123 echo '<div class="notice notice-error"><p>' . esc_html( $message ) . '</p></div>';
83 124 }
84 125
85 126 /**
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 - /**
103 127 * Check if API key is set.
104 128 *
105 129 * @return bool
106 130 */
107 - public function has_api_key() {
131 + public function has_key() {
108 132 return FLYWP_API_KEY !== '';
109 133 }
110 134
111 135 /**
@@ -112,9 +136,9 @@
112 136 * Get API key.
113 137 *
114 138 * @return string
115 139 */
116 - public function get_api_key() {
140 + public function get_key() {
117 141 return FLYWP_API_KEY;
118 142 }
119 143 }
120 144
@@ -120,9 +144,9 @@
120 144
121 145 /**
122 146 * Returns the main instance of FlyWP to prevent the need to use globals.
123 147 *
124 - * @return FlyWP
148 + * @return FlyWP_Plugin
125 149 */
126 150 function flywp() {
127 151 return FlyWP_Plugin::instance();
128 152 }