| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! class_exists( 'FL_Assistant_Plugin_Loader' ) ) { |
| 4 |
|
| 5 |
/** |
| 6 |
* Sets up plugin constants and loads the necessary PHP files. |
| 7 |
* If the plugin can't be loaded, an admin notice is shown. |
| 8 |
*/ |
| 9 |
final class FL_Assistant_Plugin_Loader { |
| 10 |
|
| 11 |
/** |
| 12 |
* Initialize the plugin. |
| 13 |
*/ |
| 14 |
static public function init() { |
| 15 |
if ( self::get_loading_error() ) { |
| 16 |
self::admin_notice_hooks(); |
| 17 |
return; |
| 18 |
} |
| 19 |
|
| 20 |
self::define_constants(); |
| 21 |
self::load_files(); |
| 22 |
|
| 23 |
register_activation_hook( FL_ASSISTANT_FILE, __CLASS__ . '::activate' ); |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Define plugin constants. |
| 28 |
*/ |
| 29 |
static private function define_constants() { |
| 30 |
define( 'FL_ASSISTANT_VERSION', '0.1' ); |
| 31 |
define( 'FL_ASSISTANT_FILE', trailingslashit( dirname( dirname( __FILE__ ) ) ) . 'fl-assistant.php' ); |
| 32 |
define( 'FL_ASSISTANT_DIR', plugin_dir_path( FL_ASSISTANT_FILE ) ); |
| 33 |
define( 'FL_ASSISTANT_URL', plugins_url( '/', FL_ASSISTANT_FILE ) ); |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Runs on plugin activation. |
| 38 |
*/ |
| 39 |
static public function activate() { |
| 40 |
do_action( 'fl_assistant_activate' ); |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Load plugin files. |
| 45 |
*/ |
| 46 |
static public function load_files() { |
| 47 |
require_once FL_ASSISTANT_DIR . 'classes/class-fl-assistant-asset-loader.php'; |
| 48 |
require_once FL_ASSISTANT_DIR . 'classes/class-fl-assistant-data.php'; |
| 49 |
include_once FL_ASSISTANT_DIR . 'classes/class-fl-assistant-heartbeat.php'; |
| 50 |
require_once FL_ASSISTANT_DIR . 'classes/class-fl-assistant-rest.php'; |
| 51 |
|
| 52 |
do_action( 'fl_assistant_loaded' ); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Initializes actions for the admin notice if the plugin can't load. |
| 57 |
*/ |
| 58 |
static private function admin_notice_hooks() { |
| 59 |
global $pagenow; |
| 60 |
|
| 61 |
if ( 'plugins.php' == $pagenow ) { |
| 62 |
add_action( 'admin_notices', __CLASS__ . '::admin_notice' ); |
| 63 |
add_action( 'network_admin_notices', __CLASS__ . '::admin_notice' ); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* Shows an admin notice if the plugin can't load. |
| 69 |
*/ |
| 70 |
static public function admin_notice() { |
| 71 |
if ( ! is_admin() ) { |
| 72 |
return; |
| 73 |
} elseif ( ! is_user_logged_in() ) { |
| 74 |
return; |
| 75 |
} elseif ( ! current_user_can( 'update_core' ) ) { |
| 76 |
return; |
| 77 |
} |
| 78 |
|
| 79 |
$message = self::get_loading_error(); |
| 80 |
|
| 81 |
if ( $message ) { |
| 82 |
echo '<div class="error">'; |
| 83 |
echo '<p>' . sprintf( $message ) . '</p>'; |
| 84 |
echo '</div>'; |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Returns a plugin loading error if there is one. |
| 90 |
*/ |
| 91 |
static private function get_loading_error() { |
| 92 |
$error = false; |
| 93 |
|
| 94 |
if ( version_compare( phpversion(), '5.6', '<' ) ) { |
| 95 |
$url = 'http://www.wpupdatephp.com/contact-host/'; |
| 96 |
/* translators: php upgrade url. */ |
| 97 |
$error = sprintf( __( 'Assistant requires PHP 5.6 or above. Please <a href="%s">update your PHP version</a> before continuing.', 'fl-assistant' ), $url ); |
| 98 |
} |
| 99 |
|
| 100 |
return $error; |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
FL_Assistant_Plugin_Loader::init(); |
| 105 |
} |
| 106 |
|