PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 4.7.0
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v4.7.0
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / vendor / team-updraft / lib-central / central / updraftplus.php

updraftplus.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 4.7.0, at vendor/team-updraft/lib-central/central/updraftplus.php

283 lines 6.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (class_exists('UpdraftPlus_Host')) return;
4
5 if (!defined('UPDRAFTCENTRAL_CLIENT_DIR')) define('UPDRAFTCENTRAL_CLIENT_DIR', dirname(__FILE__));
6 if (!defined('UPDRAFTCENTRAL_CLIENT_URL')) define('UPDRAFTCENTRAL_CLIENT_URL', plugins_url('', __FILE__));
7 if (!class_exists('UpdraftCentral_Host')) {
8 include_once(UPDRAFTCENTRAL_CLIENT_DIR.'/host.php');
9 }
10
11 /**
12 * This class is the basic bridge between UpdraftCentral and UpdraftPlus.
13 */
14 class UpdraftPlus_Host extends UpdraftCentral_Host {
15
16 public $plugin_name = 'updraftplus';
17
18 public $translations = array();
19
20 protected static $_instance = null;
21
22 /**
23 * Creates an instance of this class. Singleton Pattern
24 *
25 * @return object Instance of this class
26 */
27 public static function instance() {
28 if (empty(self::$_instance)) {
29 self::$_instance = new self();
30 }
31
32 return self::$_instance;
33 }
34
35 /**
36 * Class constructor
37 */
38 public function __construct() {
39 parent::__construct();
40
41 add_action('updraftplus_debugtools_dashboard', array($this, 'debugtools_dashboard'), 20);
42 add_action('updraftplus_load_translations_for_udcentral', array($this, 'load_updraftplus_translations'));
43
44 $this->maybe_initialize_required_objects();
45 }
46
47 /**
48 * Loads the UpdraftCentral_Main instance
49 *
50 * @return void
51 */
52 public function load_updraftcentral() {
53 $central_path = $this->is_host_dir_set() ? trailingslashit(UPDRAFTPLUS_DIR) : '';
54
55 if (file_exists($central_path.'central/bootstrap.php')) {
56 include_once($central_path.'central/bootstrap.php');
57 }
58 }
59
60 /**
61 * Whether the current user can perform key control AJAX actions
62 *
63 * @return Boolean
64 */
65 public function current_user_can_ajax() {
66 return UpdraftPlus_Options::user_can_manage();
67 }
68
69 /**
70 * Below are interface methods' implementations that are required by UpdraftCentral to function properly. Please
71 * see the "interface.php" to check all the required interface methods.
72 */
73
74 /**
75 * Checks whether the plugin's DIR constant is currently define or not
76 *
77 * @return bool
78 */
79 public function is_host_dir_set() {
80 return defined('UPDRAFTPLUS_DIR') ? true : false;
81 }
82
83 /**
84 * Get the host plugin's dir path
85 *
86 * @return string
87 */
88 public function get_host_dir() {
89 return defined('UPDRAFTPLUS_DIR') ? UPDRAFTPLUS_DIR : dirname(dirname(__FILE__));
90 }
91
92 /**
93 * Retrieves the filter used by UpdraftPlus to log errors or certain events
94 *
95 * @return string
96 */
97 public function get_logline_filter() {
98 return 'updraftplus_logline';
99 }
100
101 /**
102 * Checks whether debug mod is set
103 *
104 * @return bool
105 */
106 public function get_debug_mode() {
107 if (class_exists('UpdraftPlus_Options')) {
108 return UpdraftPlus_Options::get_updraft_option('updraft_debug_mode');
109 }
110 return false;
111 }
112
113 /**
114 * Used as a central location (to avoid repetition) to register or de-register hooks into the WP HTTP API
115 *
116 * @param bool $register True to register, false to de-register
117 * @return void
118 */
119 public function register_wp_http_option_hooks($register = true) {
120 global $updraftplus;
121
122 if ($updraftplus) {
123 $updraftplus->register_wp_http_option_hooks($register);
124 }
125 }
126
127 /**
128 * Retrieves the class name of the host plugin
129 *
130 * @return string|bool
131 */
132 public function get_class_name() {
133 global $updraftplus;
134
135 if ($updraftplus) {
136 return get_class($updraftplus);
137 }
138
139 return false;
140 }
141
142 /**
143 * Returns the instance of the host plugin
144 *
145 * @return object|bool
146 */
147 public function get_instance() {
148 global $updraftplus;
149
150 if ($updraftplus) {
151 return $updraftplus;
152 }
153
154 return false;
155 }
156
157 /**
158 * Returns the admin instance of the host plugin
159 *
160 * @return object|bool
161 */
162 public function get_admin_instance() {
163 global $updraftplus_admin;
164
165 if ($updraftplus_admin) {
166 return $updraftplus_admin;
167 } else {
168 if (defined('UPDRAFTPLUS_DIR') && file_exists(UPDRAFTPLUS_DIR.'/admin.php')) {
169 updraft_try_include_file('admin.php', 'include_once');
170 $updraftplus_admin = new UpdraftPlus_Admin();
171 return $updraftplus_admin;
172 }
173 }
174
175 return false;
176 }
177
178 /**
179 * Logs the given line
180 *
181 * @param string $line The log line
182 * @param string $level The log level: notice, warning, error, etc.
183 * @param boolean|string $uniq_id Each of these will only be logged once
184 *
185 * @return void
186 */
187 public function log($line, $level = 'notice', $uniq_id = false) {
188 global $updraftplus;
189
190 if ($updraftplus) {
191 if (is_callable(array($updraftplus, 'log'))) {
192 call_user_func(array($updraftplus, 'log'), $line, $level, $uniq_id);
193 }
194 }
195 }
196
197 /**
198 * Returns the current version of the host plugin
199 *
200 * @return string|bool
201 */
202 public function get_version() {
203 global $updraftplus;
204
205 if ($updraftplus) {
206 return $updraftplus->version;
207 }
208
209 return false;
210 }
211
212 /**
213 * Returns the filesystem class of the host's plugin
214 *
215 * @return class|bool
216 */
217 public function get_filesystem_functions() {
218 if ($this->has_filesystem_functions()) {
219 return UpdraftPlus_Filesystem_Functions;
220 }
221
222 return false;
223 }
224
225 /**
226 * Checks whether the filesystem class of the host plugin exists
227 *
228 * @return bool
229 */
230 public function has_filesystem_functions() {
231 return class_exists('UpdraftPlus_Filesystem_Functions');
232 }
233
234 /**
235 * Checks whether force debugging is set
236 *
237 * @return bool
238 */
239 public function is_force_debug() {
240 return (defined('UPDRAFTPLUS_UDRPC_FORCE_DEBUG') && UPDRAFTPLUS_UDRPC_FORCE_DEBUG) ? true : false;
241 }
242
243 /**
244 * Initializes required objects (if not yet initialized) for UpdraftCentral usage
245 *
246 * @return void
247 */
248 private function maybe_initialize_required_objects() {
249 global $updraftplus;
250
251 if (!class_exists('UpdraftPlus')) {
252 if (defined('UPDRAFTPLUS_DIR') && file_exists(UPDRAFTPLUS_DIR.'/class-updraftplus.php')) {
253 updraft_try_include_file('class-updraftplus.php', 'include_once');
254 if (empty($updraftplus) || !is_a($updraftplus, 'UpdraftPlus')) {
255 $updraftplus = new UpdraftPlus();
256 }
257 }
258 }
259
260 if (!class_exists('UpdraftPlus_Options')) {
261 if (defined('UPDRAFTPLUS_DIR') && file_exists(UPDRAFTPLUS_DIR.'/options.php')) {
262 updraft_try_include_file('options.php', 'require_once');
263 }
264 }
265
266 if (!class_exists('UpdraftPlus_Filesystem_Functions')) {
267 if (defined('UPDRAFTPLUS_DIR') && file_exists(UPDRAFTPLUS_DIR.'/includes/class-filesystem-functions.php')) {
268 updraft_try_include_file('includes/class-filesystem-functions.php', 'require_once');
269 }
270 }
271 }
272
273 /**
274 * Load translations which are based on UpdraftPlus domain text
275 */
276 public function load_updraftplus_translations() {
277 // Load updraftplus translations
278 if (defined('UPDRAFTCENTRAL_CLIENT_DIR') && file_exists(UPDRAFTCENTRAL_CLIENT_DIR.'/translations-central.php')) {
279 $this->translations = include(UPDRAFTCENTRAL_CLIENT_DIR.'/translations-central.php');
280 }
281 }
282 }
283