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

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

152 lines 3.2 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: 0.2.1
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 = '0.2.1';
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 }
57
58 /**
59 * Define plugin constants.
60 *
61 * @return void
62 */
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', '' );
72 }
73 }
74
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 );
85 }
86
87 /**
88 * Initialize plugin.
89 *
90 * @return void
91 */
92 public function init_plugin() {
93 if ( ! $this->has_key() ) {
94 $this->add_action( 'admin_notices', 'admin_notice' );
95
96 return;
97 }
98
99 if ( is_admin() ) {
100 $this->admin = new FlyWP\Admin();
101 } else {
102 $this->frontend = new FlyWP\Frontend();
103 }
104
105 $this->router = new FlyWP\Router();
106 $this->rest = new FlyWP\Api();
107 $this->fastcgi = new FlyWP\Fastcgi_Cache();
108 $this->flyapi = new FlyWP\FlyApi();
109 }
110
111 /**
112 * Show admin notice if API key is not set.
113 *
114 * @return void
115 */
116 public function admin_notice() {
117 $message = __( 'Missing FlyWP API key, plugin requires an API key.', 'flywp' );
118
119 echo '<div class="notice notice-error"><p>' . esc_html( $message ) . '</p></div>';
120 }
121
122 /**
123 * Check if API key is set.
124 *
125 * @return bool
126 */
127 public function has_key() {
128 return FLYWP_API_KEY !== '';
129 }
130
131 /**
132 * Get API key.
133 *
134 * @return string
135 */
136 public function get_key() {
137 return FLYWP_API_KEY;
138 }
139 }
140
141 /**
142 * Returns the main instance of FlyWP to prevent the need to use globals.
143 *
144 * @return FlyWP_Plugin
145 */
146 function flywp() {
147 return FlyWP_Plugin::instance();
148 }
149
150 // take off
151 flywp();
152