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
flywp / flywp.php

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

132 lines 2.6 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.1
7 * Author: FlyWP
8 * License: GPL2
9 */
10
11 // Exit if accessed directly.
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15
16 require __DIR__ . '/vendor/autoload.php';
17
18 final class FlyWP_Plugin {
19
20 /**
21 * Plugin version.
22 *
23 * @var string
24 */
25 private $version = '1.0.0';
26
27 /**
28 * The single instance of the class.
29 *
30 * @var FlyWP
31 */
32 private static $instance = null;
33
34 /**
35 * Plugin Constructor.
36 *
37 * @return void
38 */
39 private function __construct() {
40 $this->define_constants();
41
42 add_action( 'plugins_loaded', [ $this, 'init_plugin' ] );
43 }
44
45 /**
46 * Main FlyWP Instance.
47 *
48 * Ensures only one instance of FlyWP is loaded or can be loaded.
49 *
50 * @return flyWP - Main instance
51 */
52 public static function instance() {
53 if ( null === self::$instance ) {
54 self::$instance = new self();
55 }
56
57 return self::$instance;
58 }
59
60 public function init_plugin() {
61 if ( ! $this->has_api_key() ) {
62 add_action( 'admin_notices', [ $this, 'admin_notice' ] );
63
64 return;
65 }
66
67 if ( is_admin() ) {
68 new FlyWP\Admin();
69 } else {
70 new FlyWP\Frontend();
71 }
72 }
73
74 /**
75 * Show admin notice if API key is not set.
76 *
77 * @return void
78 */
79 public function admin_notice() {
80 $message = __( 'Missing FlyWP API key, plugin requires an API key.', 'flywp' );
81
82 echo '<div class="notice notice-error"><p>' . esc_html( $message ) . '</p></div>';
83 }
84
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 /**
103 * Check if API key is set.
104 *
105 * @return bool
106 */
107 public function has_api_key() {
108 return FLYWP_API_KEY !== '';
109 }
110
111 /**
112 * Get API key.
113 *
114 * @return string
115 */
116 public function get_api_key() {
117 return FLYWP_API_KEY;
118 }
119 }
120
121 /**
122 * Returns the main instance of FlyWP to prevent the need to use globals.
123 *
124 * @return FlyWP
125 */
126 function flywp() {
127 return FlyWP_Plugin::instance();
128 }
129
130 // take off
131 flywp();
132