-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBenefits.php
141 lines (121 loc) · 4.64 KB
/
Benefits.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
/**
* Plugin Name: Benefits
* Plugin URI: https://wordpress.org/plugins/benefits/
* Description: It’s a high quality, native and responsive WordPress plugin to create and view slider-based benefits
* Version: 6.1.10
* Author: KestutisIT
* Author URI: https://profiles.wordpress.org/KestutisIT
* Text Domain: benefits
* Domain Path: /Languages
* License: MIT License. See Legal/License.txt for details.
*/
namespace Benefits;
defined( 'ABSPATH' ) or die( 'No script kiddies, please!' );
// Include PHP 5.6 backwards compatibility file
require_once 'php56_compat.php';
// Require missing WordPress core functions
require_once 'formatting.php';
// Require mandatory models
require_once 'Models/Configuration/ConfigurationInterface.php';
require_once 'Models/Routing/RoutingInterface.php';
require_once 'Models/Configuration/Configuration.php';
require_once 'Models/Semver/SemverInterface.php';
require_once 'Models/Semver/Semver.php';
require_once 'Models/Validation/StaticValidator.php';
// Require autoloader and main plugin controller
require_once 'Models/Load/AutoLoad.php';
require_once 'Controllers/MainController.php';
use Benefits\Models\Configuration\Configuration;
use Benefits\Controllers\MainController;
if(!class_exists('Benefits\Benefits'))
{
final class Benefits
{
// Configuration
const REQUIRED_PHP_VERSION = '5.6.0';
const REQUIRED_WP_VERSION = 4.6;
const OLDEST_COMPATIBLE_PLUGIN_SEMVER = '6.0.0';
const PLUGIN_SEMVER = '6.1.10';
// Settings
/**
* @var array - Plugin settings. We don't use constant here, because it is supported only since PHP 5.6
*/
private static $params = array(
'plugin_prefix' => 'benefits_',
'plugin_handle_prefix' => 'benefits-',
'plugin_url_prefix' => 'benefits-',
'plugin_css_prefix' => 'benefits-',
'theme_ui_folder_name' => 'BenefitsUI', // Folder in your current theme path, that may override plugin’s UI
'plugin_name' => 'Benefits',
'shortcode' => 'benefits',
'text_domain' => 'benefits',
);
/**
* @var Configuration - Conf Without Routing
*/
private static $objConfiguration = NULL;
/**
* @var MainController - Main Controller
*/
private static $objMainController = NULL;
private static $uninstallHookRegistered = FALSE;
/**
* @return Configuration
*/
public static function getConfiguration()
{
if(is_null(static::$objConfiguration) || !(static::$objConfiguration instanceof Configuration))
{
// Create an instance of plugin configuration model
static::$objConfiguration = new Configuration(
$GLOBALS['wpdb'],
get_current_blog_id(),
static::REQUIRED_PHP_VERSION, phpversion(),
static::REQUIRED_WP_VERSION, $GLOBALS['wp_version'],
static::OLDEST_COMPATIBLE_PLUGIN_SEMVER, static::PLUGIN_SEMVER,
__FILE__,
static::$params
);
}
return static::$objConfiguration;
}
/**
* Creates new or returns existing instance of plugin main controller
* @return MainController
*/
public static function getMainController()
{
if(is_null(static::$objMainController) || !(static::$objMainController instanceof MainController))
{
// NOTE: This is not passing by reference!
static::$objMainController = new MainController(static::getConfiguration());
}
return static::$objMainController;
}
/**
* Registers plugin uninstall hook
* NOTE #1: separated from dynamic objects, because uninstall hook can be called in static context only!
*/
public static function registerUninstallHook()
{
if(static::$uninstallHookRegistered === FALSE)
{
static::$uninstallHookRegistered = TRUE;
register_uninstall_hook(__FILE__, array(__CLASS__, 'uninstall'));
}
}
public static function uninstall()
{
// This check allows us to use plugin only in the correct way
if(static::$uninstallHookRegistered === TRUE)
{
static::getMainController()->uninstall();
}
}
}
// Register static hooks
Benefits::registerUninstallHook();
// Run the plugin
Benefits::getMainController()->run();
}