| @@ -14,20 +14,21 @@ | ||
| 14 | 14 | use WPIDE\App\Kernel\Response; |
| 15 | 15 | use WPIDE\App\Kernel\StreamedResponse; |
| 16 | 16 | use WPIDE\App\Services\Services; |
| 17 | 17 | use WPIDE\App\Services\Storage\LocalFileSystem; |
| 18 | -use WPIDE\App\Tasks\TestTask; | |
| 19 | -use const WPIDE\Constants\ASSETS_URL; | |
| 20 | 18 | use const WPIDE\Constants\AUTHOR; |
| 21 | 19 | use const WPIDE\Constants\CONTENT_DIR; |
| 22 | 20 | use const WPIDE\Constants\DIR; |
| 23 | 21 | use const WPIDE\Constants\TMP_DIR; |
| 24 | 22 | use const WPIDE\Constants\URL; |
| 23 | +use const WPIDE\Constants\ASSETS_URL; | |
| 25 | 24 | use const WPIDE\Constants\FATAL_ERROR_DROPIN; |
| 25 | +use const WPIDE\Constants\FATAL_ERROR_DROPIN_VERSION; | |
| 26 | +use const WPIDE\Constants\FATAL_ERROR_DROPIN_VERSION_OPT; | |
| 26 | 27 | use const WPIDE\Constants\NAME; |
| 27 | 28 | use const WPIDE\Constants\SLUG; |
| 28 | 29 | use const WPIDE\Constants\PLUGIN_URL; |
| 29 | -use const WPIDE\Constants\REQUIRED_PHP_VERSION; | |
| 30 | +use const WPIDE\Constants\VERSION; | |
| 30 | 31 | |
| 31 | 32 | class App |
| 32 | 33 | { |
| 33 | 34 | public static $_instance; |
| @@ -85,16 +86,34 @@ | ||
| 85 | 86 | { |
| 86 | 87 | return SLUG . (!empty($suffix) ? '_' . $suffix : ''); |
| 87 | 88 | } |
| 88 | 89 | |
| 90 | + public function isLatestDropIn(): bool | |
| 91 | + { | |
| 92 | + | |
| 93 | + $currentVersion = get_option(FATAL_ERROR_DROPIN_VERSION_OPT, null); | |
| 94 | + | |
| 95 | + return $currentVersion === FATAL_ERROR_DROPIN_VERSION; | |
| 96 | + } | |
| 97 | + | |
| 98 | + public function dropInExists() { | |
| 99 | + | |
| 100 | + $fs = LocalFileSystem::load(CONTENT_DIR); | |
| 101 | + | |
| 102 | + return $fs->fileExists(FATAL_ERROR_DROPIN); | |
| 103 | + } | |
| 104 | + | |
| 89 | 105 | public function installDropIn() { |
| 90 | 106 | |
| 91 | 107 | $fs = LocalFileSystem::load(CONTENT_DIR); |
| 92 | 108 | |
| 93 | - if(!$fs->fileExists(FATAL_ERROR_DROPIN)) { | |
| 109 | + if($fs->fileExists(FATAL_ERROR_DROPIN)) { | |
| 110 | + $this->unInstallDropIn(); | |
| 111 | + } | |
| 94 | 112 | |
| 95 | - $fs->copyFile('plugins/'.basename(DIR).'/wp-content/'.FATAL_ERROR_DROPIN, './'); | |
| 96 | - } | |
| 113 | + $fs->copyFile('plugins/'.basename(DIR).'/wp-content/'.FATAL_ERROR_DROPIN, './'); | |
| 114 | + | |
| 115 | + update_option(FATAL_ERROR_DROPIN_VERSION_OPT, FATAL_ERROR_DROPIN_VERSION); | |
| 97 | 116 | } |
| 98 | 117 | |
| 99 | 118 | public function unInstallDropIn() { |
| 100 | 119 | |
| @@ -111,8 +130,12 @@ | ||
| 111 | 130 | if(!$this->dependencyCheck() || !is_admin()) { |
| 112 | 131 | return; |
| 113 | 132 | } |
| 114 | 133 | |
| 134 | + if(!$this->dropInExists() || !$this->isLatestDropIn()) { | |
| 135 | + $this->installDropIn(); | |
| 136 | + } | |
| 137 | + | |
| 115 | 138 | $this->loadTextDomain(); |
| 116 | 139 | $this->loadHooks(); |
| 117 | 140 | |
| 118 | 141 | Migrations::init(); |
| @@ -135,22 +158,13 @@ | ||
| 135 | 158 | if(!empty($this->dependencyNotice)) { |
| 136 | 159 | echo $this->dependencyNotice; |
| 137 | 160 | } |
| 138 | 161 | |
| 139 | - if (version_compare(PHP_VERSION, REQUIRED_PHP_VERSION, '<')) { | |
| 162 | + // Perform checks here | |
| 163 | + // $class = 'notice notice-error'; | |
| 164 | + // $message = ''; | |
| 165 | + // $this->dependencyNotice = sprintf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), $message); | |
| 140 | 166 | |
| 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 | 167 | if(!empty($this->dependencyNotice)) { |
| 154 | 168 | add_action('admin_notices', [$this, 'dependencyCheck']); |
| 155 | 169 | return false; |
| 156 | 170 | } |
| @@ -161,15 +175,17 @@ | ||
| 161 | 175 | protected function loadHooks() |
| 162 | 176 | { |
| 163 | 177 | |
| 164 | 178 | add_action('admin_menu', [$this, 'adminMenu' ]); |
| 165 | - add_action("wpide_ajax_request", [$this, "ajaxRequest"]); | |
| 179 | + add_action("wp_ajax_wpide_request", [$this, "ajaxRequest"]); | |
| 166 | 180 | add_action("admin_init", [$this, "registerTasks"]); |
| 181 | + add_action('admin_enqueue_scripts', [ $this, 'enqueueCommonAssets' ]); | |
| 167 | 182 | |
| 168 | 183 | if($this->isPluginScreen()) { |
| 169 | 184 | |
| 170 | 185 | add_filter('admin_title', [$this, 'setAdminTitle']); |
| 171 | 186 | add_action('admin_head', [$this, 'addAdminFavicon']); |
| 187 | + add_action("admin_menu", [$this, "setCurrentScreen"], -1); | |
| 172 | 188 | add_action('admin_menu', [Notices::class, 'init']); |
| 173 | 189 | add_filter('screen_options_show_screen', '__return_false'); |
| 174 | 190 | add_filter('admin_body_class', [$this, 'bodyClasses'], 10, 1); |
| 175 | 191 | add_action('admin_enqueue_scripts', [ $this, 'deregisterWpStyles' ]); |
| @@ -177,11 +193,16 @@ | ||
| 177 | 193 | } |
| 178 | 194 | |
| 179 | 195 | public function registerTasks() { |
| 180 | 196 | |
| 181 | - TestTask::register(); | |
| 197 | + //TestTask::register(); | |
| 182 | 198 | } |
| 183 | 199 | |
| 200 | + public function setCurrentScreen() { | |
| 201 | + | |
| 202 | + set_current_screen(SLUG); | |
| 203 | + } | |
| 204 | + | |
| 184 | 205 | public function canManage(): bool |
| 185 | 206 | { |
| 186 | 207 | return current_user_can('manage_options'); |
| 187 | 208 | } |
| @@ -252,8 +273,11 @@ | ||
| 252 | 273 | $this->container->set(StreamedResponse::class, $sresponse); |
| 253 | 274 | |
| 254 | 275 | $this->services = []; |
| 255 | 276 | foreach ($services->get() as $key => $service) { |
| 277 | + if(empty($service['handler'])) { | |
| 278 | + continue; | |
| 279 | + } | |
| 256 | 280 | $this->container->set($key, $this->container->get($service['handler'])); |
| 257 | 281 | $this->container->get($key)->init(isset($service['config']) ? $service['config'] : []); |
| 258 | 282 | $this->services[$key] = $this->container->get($key); |
| 259 | 283 | } |
| @@ -309,8 +333,14 @@ | ||
| 309 | 333 | wp_register_style('site-icon', null); |
| 310 | 334 | |
| 311 | 335 | } |
| 312 | 336 | |
| 337 | + public function enqueueCommonAssets() | |
| 338 | + { | |
| 339 | + | |
| 340 | + wp_enqueue_style(SLUG.'-fs-notices', ASSETS_URL.'global/css/fs-notices.css', [], VERSION); | |
| 341 | + } | |
| 342 | + | |
| 313 | 343 | public function ajaxRequest() |
| 314 | 344 | { |
| 315 | 345 | if(!$this->canManage()) { |
| 316 | 346 | die(esc_html__('Restricted Access', 'wpide')); |
| @@ -342,11 +372,15 @@ | ||
| 342 | 372 | |
| 343 | 373 | return false; |
| 344 | 374 | } |
| 345 | 375 | |
| 346 | - public function isFreemiusScreen(): bool | |
| 376 | + public function isFreemiusScreen($section = null): bool | |
| 347 | 377 | { |
| 348 | 378 | |
| 379 | + if($section) { | |
| 380 | + return $this->isPluginScreen($section); | |
| 381 | + } | |
| 382 | + | |
| 349 | 383 | if( |
| 350 | 384 | $this->isPluginScreen('account') || |
| 351 | 385 | $this->isPluginScreen('pricing') || |
| 352 | 386 | $this->isPluginScreen('contact') || |
| @@ -364,9 +398,9 @@ | ||
| 364 | 398 | } |
| 365 | 399 | |
| 366 | 400 | public function getAjaxUrl($req = ''): string |
| 367 | 401 | { |
| 368 | - return URL.'ajax.php?action=request&req='.$req; | |
| 402 | + return admin_url('admin-ajax.php').'?action=wpide_request&req='.$req; | |
| 369 | 403 | } |
| 370 | 404 | |
| 371 | 405 | /** |
| 372 | 406 | * Get external url with utm campaign / content |