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 +42 -82 1.10.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.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,36 +14,25 @@
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.1';
25 + private $version = '1.0.0';
45 26
46 27 /**
28 + * The single instance of the class.
29 + *
30 + * @var FlyWP
31 + */
32 + private static $instance = null;
33 +
34 + /**
47 35 * Plugin Constructor.
48 36 *
49 37 * @return void
50 38 */
@@ -50,65 +38,38 @@
50 38 */
51 39 private function __construct() {
52 40 $this->define_constants();
53 41
54 - $this->add_action( 'plugins_loaded', 'init_plugin' );
55 - register_activation_hook( __FILE__, [ $this, 'activate' ] );
42 + add_action( 'plugins_loaded', [ $this, 'init_plugin' ] );
56 43 }
57 44
58 45 /**
59 - * Define plugin constants.
46 + * Main FlyWP Instance.
60 47 *
61 - * @return void
48 + * Ensures only one instance of FlyWP is loaded or can be loaded.
49 + *
50 + * @return flyWP - Main instance
62 51 */
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__ ) );
69 -
70 - if ( ! defined( 'FLYWP_API_KEY' ) ) {
71 - define( 'FLYWP_API_KEY', '' );
52 + public static function instance() {
53 + if ( null === self::$instance ) {
54 + self::$instance = new self();
72 55 }
73 - }
74 56
75 - /**
76 - * Plugin activation hook.
77 - *
78 - * @return void
79 - */
80 - public function activate() {
81 - $router = new FlyWP\Router();
82 - $router->register_routes();
83 -
84 - flush_rewrite_rules( false );
57 + return self::$instance;
85 58 }
86 59
87 - /**
88 - * Initialize plugin.
89 - *
90 - * @return void
91 - */
92 60 public function init_plugin() {
93 - if ( ! $this->has_key() ) {
94 - $this->add_action( 'admin_notices', 'admin_notice' );
61 + if ( ! $this->has_api_key() ) {
62 + add_action( 'admin_notices', [ $this, 'admin_notice' ] );
95 63
96 64 return;
97 65 }
98 66
99 67 if ( is_admin() ) {
100 - $this->admin = new FlyWP\Admin();
68 + new FlyWP\Admin();
101 69 } else {
102 - $this->frontend = new FlyWP\Frontend();
70 + new FlyWP\Frontend();
103 71 }
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 72 }
112 73
113 74 /**
114 75 * Show admin notice if API key is not set.
@@ -121,13 +82,30 @@
121 82 echo '<div class="notice notice-error"><p>' . esc_html( $message ) . '</p></div>';
122 83 }
123 84
124 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 + /**
125 103 * Check if API key is set.
126 104 *
127 105 * @return bool
128 106 */
129 - public function has_key() {
107 + public function has_api_key() {
130 108 return FLYWP_API_KEY !== '';
131 109 }
132 110
133 111 /**
@@ -134,35 +112,17 @@
134 112 * Get API key.
135 113 *
136 114 * @return string
137 115 */
138 - public function get_key() {
116 + public function get_api_key() {
139 117 return FLYWP_API_KEY;
140 118 }
141 -
142 - /**
143 - * Debugging helper.
144 - *
145 - * @param mixed $value
146 - * @param bool $die
147 - *
148 - * @return void
149 - */
150 - public function debug( $value, $die = false ) {
151 - echo '<pre>';
152 - print_r( $value );
153 - echo '</pre>';
154 -
155 - if ( $die ) {
156 - die();
157 - }
158 - }
159 119 }
160 120
161 121 /**
162 122 * Returns the main instance of FlyWP to prevent the need to use globals.
163 123 *
164 - * @return FlyWP_Plugin
124 + * @return FlyWP
165 125 */
166 126 function flywp() {
167 127 return FlyWP_Plugin::instance();
168 128 }