| @@ -92,8 +92,9 @@ | ||
| 92 | 92 | continue; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | $space = Space::create($spaceData); |
| 96 | + /** @var Space $space */ | |
| 96 | 97 | Helper::addToSpace($space, get_current_user_id(), 'admin'); |
| 97 | 98 | } |
| 98 | 99 | |
| 99 | 100 | return true; |
| @@ -239,8 +240,9 @@ | ||
| 239 | 240 | continue; |
| 240 | 241 | } |
| 241 | 242 | |
| 242 | 243 | $space = Space::create($spaceData); |
| 244 | + /** @var Space $space */ | |
| 243 | 245 | Helper::addToSpace($space, get_current_user_id(), 'admin'); |
| 244 | 246 | } |
| 245 | 247 | } |
| 246 | 248 | |
| @@ -275,10 +277,12 @@ | ||
| 275 | 277 | } |
| 276 | 278 | |
| 277 | 279 | $url = 'https://fluentcommunity.co/discount-deal/?fluentcrm=1&route=contact&hash=8850223d-c62d-4e6a-8108-b04c7e9e4fdb'; |
| 278 | 280 | |
| 279 | - $response = wp_remote_post($url, [ | |
| 280 | - 'body' => json_encode([ // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode | |
| 281 | + $response = wp_safe_remote_post($url, [ | |
| 282 | + 'timeout' => 10, | |
| 283 | + 'redirection' => 0, | |
| 284 | + 'body' => json_encode([ // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode | |
| 281 | 285 | 'full_name' => $userFullName, |
| 282 | 286 | 'email' => $userEmail, |
| 283 | 287 | 'source' => 'fcom_plugin', |
| 284 | 288 | 'optin_website' => home_url(), |
| @@ -326,9 +330,9 @@ | ||
| 326 | 330 | return new \WP_Error('plugin_install_error', $exception->getMessage()); |
| 327 | 331 | } |
| 328 | 332 | } |
| 329 | 333 | |
| 330 | - private static function backgroundInstaller($plugin_to_install) | |
| 334 | + public static function backgroundInstaller($plugin_to_install) | |
| 331 | 335 | { |
| 332 | 336 | if (!empty($plugin_to_install['repo-slug'])) { |
| 333 | 337 | require_once ABSPATH . 'wp-admin/includes/file.php'; |
| 334 | 338 | require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; |
| @@ -338,9 +342,9 @@ | ||
| 338 | 342 | WP_Filesystem(); |
| 339 | 343 | |
| 340 | 344 | $skin = new \Automatic_Upgrader_Skin(); |
| 341 | 345 | $upgrader = new \WP_Upgrader($skin); |
| 342 | - $installed_plugins = array_keys(\get_plugins()); | |
| 346 | + $installed_plugins = array_reduce(array_keys(\get_plugins()), array(self::class, 'associate_plugin_file'), array()); | |
| 343 | 347 | $plugin_slug = $plugin_to_install['repo-slug']; |
| 344 | 348 | $plugin_file = isset($plugin_to_install['file']) ? $plugin_to_install['file'] : $plugin_slug . '.php'; |
| 345 | 349 | $installed = false; |
| 346 | 350 | $activate = false; |
| @@ -414,15 +418,12 @@ | ||
| 414 | 418 | throw new \Exception(wp_kses_post($result->get_error_message())); |
| 415 | 419 | } |
| 416 | 420 | |
| 417 | 421 | $activate = true; |
| 418 | - | |
| 419 | - } catch (\Exception $e) { | |
| 420 | - throw new \Exception(esc_html($e->getMessage())); | |
| 422 | + } finally { | |
| 423 | + // Discard feedback. | |
| 424 | + ob_end_clean(); | |
| 421 | 425 | } |
| 422 | - | |
| 423 | - // Discard feedback. | |
| 424 | - ob_end_clean(); | |
| 425 | 426 | } |
| 426 | 427 | |
| 427 | 428 | wp_clean_plugins_cache(); |
| 428 | 429 | |
| @@ -427,17 +428,21 @@ | ||
| 427 | 428 | wp_clean_plugins_cache(); |
| 428 | 429 | |
| 429 | 430 | // Activate this thing. |
| 430 | 431 | if ($activate) { |
| 431 | - try { | |
| 432 | - $result = activate_plugin($installed ? $installed_plugins[$plugin_file] : $plugin_slug . '/' . $plugin_file); | |
| 432 | + $result = activate_plugin($installed ? $installed_plugins[$plugin_file] : $plugin_slug . '/' . $plugin_file); | |
| 433 | 433 | |
| 434 | - if (is_wp_error($result)) { | |
| 435 | - throw new \Exception(esc_html($result->get_error_message())); | |
| 436 | - } | |
| 437 | - } catch (\Exception $e) { | |
| 438 | - throw new \Exception(esc_html($e->getMessage())); | |
| 434 | + if (is_wp_error($result)) { | |
| 435 | + throw new \Exception(wp_kses_post($result->get_error_message())); | |
| 439 | 436 | } |
| 440 | 437 | } |
| 441 | 438 | } |
| 439 | + } | |
| 440 | + | |
| 441 | + private static function associate_plugin_file($plugins, $key) | |
| 442 | + { | |
| 443 | + $path = explode('/', $key); | |
| 444 | + $filename = end($path); | |
| 445 | + $plugins[$filename] = $key; | |
| 446 | + return $plugins; | |
| 442 | 447 | } |
| 443 | 448 | } |