PluginProbe
WPIDE – File Manager & Code Editor / 3.5.5
WPIDE – File Manager & Code Editor v3.5.5
3.5.8 3.5.7 2.0.14 2.0.15 2.0.16 2.0.2 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1 2.2 2.3 2.3.1 2.3.2 2.4.0 2.5 2.6 3.0 3.1 3.2 3.3 3.4 All 54 releases
← All changes | App/App.php +205 -75 3.23.5.5 View file →
@@ -1,9 +1,11 @@
1 1 <?php
2 2 namespace WPIDE\App;
3 3
4 +use WPIDE\App\Classes\Freemius;
4 5 use WPIDE\App\Classes\Migrations;
5 6 use WPIDE\App\Classes\RecommendedPlugins;
7 +use WPIDE\App\Classes\PromoNotice;
6 8 use WPIDE\App\Classes\ReviewNotice;
7 9 use WPIDE\App\Classes\Notices;
8 10 use WPIDE\App\Config\Config;
9 11 use WPIDE\App\Container\Container;
@@ -18,16 +20,16 @@
18 20 use const WPIDE\Constants\AUTHOR;
19 21 use const WPIDE\Constants\CONTENT_DIR;
20 22 use const WPIDE\Constants\DIR;
21 23 use const WPIDE\Constants\TMP_DIR;
22 -use const WPIDE\Constants\URL;
23 24 use const WPIDE\Constants\ASSETS_URL;
24 25 use const WPIDE\Constants\FATAL_ERROR_DROPIN;
26 +use const WPIDE\Constants\FATAL_ERROR_DROPIN_VERSION;
27 +use const WPIDE\Constants\FATAL_ERROR_DROPIN_VERSION_OPT;
25 28 use const WPIDE\Constants\NAME;
26 29 use const WPIDE\Constants\SLUG;
27 30 use const WPIDE\Constants\PLUGIN_URL;
28 31 use const WPIDE\Constants\VERSION;
29 -use const WPIDE\Constants\REQUIRED_PHP_VERSION;
30 32
31 33 class App
32 34 {
33 35 public static $_instance;
@@ -33,8 +35,9 @@
33 35 public static $_instance;
34 36
35 37 private $container;
36 38 private $dependencyNotice;
39 + private $isNetworkActive;
37 40
38 41 protected $notices = [];
39 42 public $services = [];
40 43
@@ -75,8 +78,17 @@
75 78
76 79 return $this->resolve('WPIDE\App\Services\Cache\Cache');
77 80 }
78 81
82 + /**
83 + * @throws \DI\DependencyException
84 + * @throws \DI\NotFoundException
85 + */
86 + public function transient() {
87 +
88 + return $this->resolve('WPIDE\App\Services\Transient\Transient');
89 + }
90 +
79 91 public function call($callable, array $parameters)
80 92 {
81 93 return $this->container->call($callable, $parameters);
82 94 }
@@ -85,16 +97,34 @@
85 97 {
86 98 return SLUG . (!empty($suffix) ? '_' . $suffix : '');
87 99 }
88 100
101 + public function isLatestDropIn(): bool
102 + {
103 +
104 + $currentVersion = get_option(FATAL_ERROR_DROPIN_VERSION_OPT, null);
105 +
106 + return $currentVersion === FATAL_ERROR_DROPIN_VERSION;
107 + }
108 +
109 + public function dropInExists(): bool
110 + {
111 + $fs = LocalFileSystem::load(CONTENT_DIR);
112 +
113 + return $fs->fileExists(FATAL_ERROR_DROPIN);
114 + }
115 +
89 116 public function installDropIn() {
90 117
91 118 $fs = LocalFileSystem::load(CONTENT_DIR);
92 119
93 - if(!$fs->fileExists(FATAL_ERROR_DROPIN)) {
120 + if($fs->fileExists(FATAL_ERROR_DROPIN)) {
121 + $this->unInstallDropIn();
122 + }
94 123
95 - $fs->copyFile('plugins/'.basename(DIR).'/wp-content/'.FATAL_ERROR_DROPIN, './');
96 - }
124 + $fs->copyFile('plugins/'.basename(DIR).'/wp-content/'.FATAL_ERROR_DROPIN, './');
125 +
126 + update_option(FATAL_ERROR_DROPIN_VERSION_OPT, FATAL_ERROR_DROPIN_VERSION);
97 127 }
98 128
99 129 public function unInstallDropIn() {
100 130
@@ -104,8 +134,11 @@
104 134 $fs->deleteFile(FATAL_ERROR_DROPIN);
105 135 }
106 136 }
107 137
138 + /**
139 + * @throws \Exception
140 + */
108 141 public function load()
109 142 {
110 143
111 144 if(!$this->dependencyCheck() || !is_admin()) {
@@ -111,13 +144,20 @@
111 144 if(!$this->dependencyCheck() || !is_admin()) {
112 145 return;
113 146 }
114 147
148 + if(!$this->dropInExists() || !$this->isLatestDropIn()) {
149 + $this->installDropIn();
150 + }
151 +
115 152 $this->loadTextDomain();
116 153 $this->loadHooks();
117 154
118 155 Migrations::init();
119 - ReviewNotice::init();
156 + PromoNotice::init();
157 + if(!PromoNotice::enabled()) {
158 + ReviewNotice::init();
159 + }
120 160 RecommendedPlugins::init();
121 161 }
122 162
123 163 protected function loadTextDomain() {
@@ -135,22 +175,13 @@
135 175 if(!empty($this->dependencyNotice)) {
136 176 echo $this->dependencyNotice;
137 177 }
138 178
139 - if (version_compare(PHP_VERSION, REQUIRED_PHP_VERSION, '<')) {
179 + // Perform checks here
180 + // $class = 'notice notice-error';
181 + // $message = '';
182 + // $this->dependencyNotice = sprintf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), $message);
140 183
141 - $class = 'notice notice-error';
142 -
143 - $message = sprintf(
144 - __( '%s minimum PHP version requirement is %s. You are using: %s', 'wpide' ),
145 - '<strong>'.NAME.'</strong>',
146 - '<strong>'.REQUIRED_PHP_VERSION.'</strong>',
147 - '<strong>'.PHP_VERSION.'</strong>'
148 - );
149 -
150 - $this->dependencyNotice = sprintf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), $message);
151 - }
152 -
153 184 if(!empty($this->dependencyNotice)) {
154 185 add_action('admin_notices', [$this, 'dependencyCheck']);
155 186 return false;
156 187 }
@@ -160,20 +191,36 @@
160 191
161 192 protected function loadHooks()
162 193 {
163 194
164 - add_action('admin_menu', [$this, 'adminMenu' ]);
165 - add_action("wpide_ajax_request", [$this, "ajaxRequest"]);
195 + if($this->showAdminMenu()) {
196 + add_action('admin_menu', [$this, 'adminMenu' ]);
197 + add_action('network_admin_menu', [$this, 'adminMenu']);
198 + }
199 +
200 + add_action("wp_ajax_wpide_request", [$this, "ajaxRequest"]);
166 201 add_action("admin_init", [$this, "registerTasks"]);
167 202 add_action('admin_enqueue_scripts', [ $this, 'enqueueCommonAssets' ]);
168 203
169 204 if($this->isPluginScreen()) {
170 205
206 + // When network active, If trying to load plugin admin url, redirect back to network root
207 + if(!$this->showAdminMenu() && !$this->isFreemiusScreen() && !Freemius::sdk()->is_activation_mode() && !Freemius::showSubmenus()) {
208 + wp_redirect(network_admin_url());
209 + die();
210 + }
211 +
171 212 add_filter('admin_title', [$this, 'setAdminTitle']);
213 +
214 + add_action('network_admin_menu', [$this, 'addAdminFavicon']);
215 + add_action("network_admin_menu", [$this, "setCurrentScreen"], -1);
216 + add_action('network_admin_menu', [Notices::class, 'init']);
217 +
172 218 add_action('admin_head', [$this, 'addAdminFavicon']);
219 + add_action("admin_menu", [$this, "setCurrentScreen"], -1);
173 220 add_action('admin_menu', [Notices::class, 'init']);
221 +
174 222 add_filter('screen_options_show_screen', '__return_false');
175 - add_filter('admin_body_class', [$this, 'bodyClasses'], 10, 1);
176 223 add_action('admin_enqueue_scripts', [ $this, 'deregisterWpStyles' ]);
177 224 }
178 225 }
179 226
@@ -181,16 +228,73 @@
181 228
182 229 //TestTask::register();
183 230 }
184 231
232 + public function setCurrentScreen() {
233 +
234 + set_current_screen(SLUG);
235 + }
236 +
185 237 public function canManage(): bool
186 238 {
187 239 return current_user_can('manage_options');
188 240 }
189 241
242 + public function showAdminMenu(): bool
243 + {
244 +
245 + if(fs_is_network_admin()) {
246 +
247 + return $this->isNetworkActive() && (WP_FS__SHOW_NETWORK_EVEN_WHEN_DELEGATED || !Freemius::sdk()->is_network_delegated_connection());
248 + }
249 +
250 + return true;
251 + }
252 +
190 253 public function adminMenu()
191 254 {
192 255
256 + $menuTopItems = apply_filters('wpide_admin_menu_top_items', [
257 + [
258 + 'title' => __( 'File Manager', 'wpide' ),
259 + 'slug' => SLUG.'#/file-manager',
260 + 'callback' => [$this, 'bootstrap'],
261 + 'position' => 10
262 + ],
263 + [
264 + 'title' => __( 'File Editor', 'wpide' ),
265 + 'slug' => SLUG.'#/file-editor',
266 + 'callback' => [$this, 'bootstrap'],
267 + 'position' => 20
268 + ],
269 + [
270 + 'title' => __( 'Image Editor', 'wpide' ),
271 + 'slug' => SLUG.'#/image-editor',
272 + 'callback' => [$this, 'bootstrap'],
273 + 'position' => 20
274 + ],
275 + [
276 + 'title' => __( 'DB Manager', 'wpide' ),
277 + 'slug' => SLUG.'#/db-manager',
278 + 'callback' => [$this, 'bootstrap'],
279 + 'position' => 30
280 + ],
281 + [
282 + 'title' => __( 'Config Manager', 'wpide' ),
283 + 'slug' => SLUG.'#/config-manager',
284 + 'callback' => [$this, 'bootstrap'],
285 + 'position' => 30
286 + ],
287 + [
288 + 'title' => __( 'Settings', 'wpide' ),
289 + 'slug' => SLUG.'#/settings',
290 + 'callback' => [$this, 'bootstrap'],
291 + 'position' => 40
292 + ]
293 + ]);
294 +
295 + $menuBottomItems = apply_filters('wpide_admin_menu_bottom_items', []);
296 +
193 297 add_menu_page(
194 298 NAME,
195 299 NAME,
196 300 'manage_options',
@@ -195,43 +299,54 @@
195 299 NAME,
196 300 'manage_options',
197 301 SLUG,
198 302 [$this, 'bootstrap'],
199 - 'dashicons-editor-code',
200 - 3
303 + 'dashicons-editor-code'
201 304 );
202 305
203 - add_submenu_page(
204 - SLUG,
205 - __( 'File Manager', 'wpide' ),
206 - __( 'File Manager', 'wpide' ),
207 - 'manage_options',
208 - SLUG.'#/file-manager',
209 - [$this, 'bootstrap'],
210 - 3
211 - );
306 + $highestPosition = 0;
307 + foreach ($menuTopItems as $item) {
308 + add_submenu_page(
309 + SLUG,
310 + $item['title'],
311 + $item['title'],
312 + 'manage_options',
313 + $item['slug'],
314 + $item['callback'],
315 + $item['position']
316 + );
212 317
318 + if ($item['position'] > $highestPosition) {
319 + $highestPosition = $item['position'];
320 + }
321 + }
322 +
213 323 add_submenu_page(
214 324 SLUG,
215 - __( 'File Editor', 'wpide' ),
216 - __( 'File Editor', 'wpide' ),
325 + '',
326 + '',
217 327 'manage_options',
218 - SLUG.'#/file-editor',
219 - [$this, 'bootstrap'],
220 - 3
328 + '#divider',
329 + '',
330 + $highestPosition + 10
221 331 );
222 332
223 - add_submenu_page(
224 - SLUG,
225 - __( 'DB Manager', 'wpide' ),
226 - __( 'DB Manager', 'wpide' ),
227 - 'manage_options',
228 - SLUG.'#/db-manager',
229 - [$this, 'bootstrap'],
230 - 3
231 - );
333 + foreach ($menuBottomItems as $item) {
334 + add_submenu_page(
335 + SLUG,
336 + $item['title'],
337 + $item['title'],
338 + 'manage_options',
339 + $item['slug'],
340 + $item['callback'],
341 + $item['position']
342 + );
343 + }
232 344
233 345 remove_submenu_page(SLUG, SLUG);
346 +
347 + do_action('wpide_admin_menu');
348 +
234 349 }
235 350
236 351 public function bootstrap() {
237 352
@@ -253,8 +368,11 @@
253 368 $this->container->set(StreamedResponse::class, $sresponse);
254 369
255 370 $this->services = [];
256 371 foreach ($services->get() as $key => $service) {
372 + if(empty($service['handler'])) {
373 + continue;
374 + }
257 375 $this->container->set($key, $this->container->get($service['handler']));
258 376 $this->container->get($key)->init(isset($service['config']) ? $service['config'] : []);
259 377 $this->services[$key] = $this->container->get($key);
260 378 }
@@ -267,18 +385,8 @@
267 385 }
268 386 }
269 387 }
270 388
271 - public function bodyClasses($classes): string
272 - {
273 -
274 - if(!$this->isFreemiusScreen()) {
275 - $classes = $classes . " folded";
276 - }
277 -
278 - return $classes;
279 - }
280 -
281 389 public function deregisterWpStyles()
282 390 {
283 391
284 392 wp_deregister_style('color');
@@ -294,21 +402,21 @@
294 402 wp_deregister_style('widgets');
295 403 wp_deregister_style('l10n');
296 404 wp_deregister_style('site-icon');
297 405
298 - wp_register_style('color', null);
299 - wp_register_style('forms', null);
300 - wp_register_style('dashboard', null);
301 - wp_register_style('list-tables', null);
302 - wp_register_style('edit', null);
303 - wp_register_style('revisions', null);
304 - wp_register_style('media', null);
305 - wp_register_style('themes', null);
306 - wp_register_style('about', null);
307 - wp_register_style('nav-menus', null);
308 - wp_register_style('widgets', null);
309 - wp_register_style('l10n', null);
310 - wp_register_style('site-icon', null);
406 + wp_register_style('color', '');
407 + wp_register_style('forms', '');
408 + wp_register_style('dashboard', '');
409 + wp_register_style('list-tables', '');
410 + wp_register_style('edit', '');
411 + wp_register_style('revisions', '');
412 + wp_register_style('media', '');
413 + wp_register_style('themes', '');
414 + wp_register_style('about', '');
415 + wp_register_style('nav-menus', '');
416 + wp_register_style('widgets', '');
417 + wp_register_style('l10n', '');
418 + wp_register_style('site-icon', '');
311 419
312 420 }
313 421
314 422 public function enqueueCommonAssets()
@@ -313,9 +421,9 @@
313 421
314 422 public function enqueueCommonAssets()
315 423 {
316 424
317 - wp_enqueue_style(SLUG.'-fs-notices', ASSETS_URL.'global/css/fs-notices.css', [], VERSION);
425 + wp_enqueue_style(SLUG.'-fs-notices', ASSETS_URL.'global/css/global.css', [], VERSION);
318 426 }
319 427
320 428 public function ajaxRequest()
321 429 {
@@ -349,11 +457,15 @@
349 457
350 458 return false;
351 459 }
352 460
353 - public function isFreemiusScreen(): bool
461 + public function isFreemiusScreen($section = null): bool
354 462 {
355 463
464 + if($section) {
465 + return $this->isPluginScreen($section);
466 + }
467 +
356 468 if(
357 469 $this->isPluginScreen('account') ||
358 470 $this->isPluginScreen('pricing') ||
359 471 $this->isPluginScreen('contact') ||
@@ -364,16 +476,34 @@
364 476
365 477 return false;
366 478 }
367 479
368 - public function getAdminUrl(): string {
480 + public function isNetworkActive(): bool
481 + {
369 482
370 - return admin_url( 'admin.php?page='.SLUG );
483 + if(!isset($this->isNetworkActive)) {
484 +
485 + $plugin = basename(WPIDE_DIR) . '/' . basename(WPIDE_FILE);
486 + $this->isNetworkActive = is_plugin_active_for_network($plugin);
487 + }
488 +
489 + return $this->isNetworkActive;
371 490 }
372 491
492 + public function getAdminUrl($section = null, $network = false): string {
493 +
494 + $admin_url_function = $network ? 'network_admin_url' : 'admin_url';
495 +
496 + $url = 'admin.php?page='.SLUG;
497 + if(!empty($section)) {
498 + $url .= '#/'.$section;
499 + }
500 + return $admin_url_function( $url );
501 + }
502 +
373 503 public function getAjaxUrl($req = ''): string
374 504 {
375 - return URL.'ajax.php?action=request&req='.$req;
505 + return admin_url('admin-ajax.php').'?action=wpide_request&req='.$req;
376 506 }
377 507
378 508 /**
379 509 * Get external url with utm campaign / content