| @@ -1,9 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace FluentCommunity\App\Services; |
| 4 | 4 | |
| 5 | -use FluentCommunity\App\Functions\Utility; | |
| 6 | 5 | use FluentCommunity\App\Models\Space; |
| 7 | 6 | use FluentCommunity\App\Models\SpaceGroup; |
| 8 | 7 | use FluentCommunity\Framework\Support\Arr; |
| 9 | 8 | use FluentCommunity\Modules\Course\Model\Course; |
| @@ -93,8 +92,9 @@ | ||
| 93 | 92 | continue; |
| 94 | 93 | } |
| 95 | 94 | |
| 96 | 95 | $space = Space::create($spaceData); |
| 96 | + /** @var Space $space */ | |
| 97 | 97 | Helper::addToSpace($space, get_current_user_id(), 'admin'); |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | return true; |
| @@ -240,8 +240,9 @@ | ||
| 240 | 240 | continue; |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | $space = Space::create($spaceData); |
| 244 | + /** @var Space $space */ | |
| 244 | 245 | Helper::addToSpace($space, get_current_user_id(), 'admin'); |
| 245 | 246 | } |
| 246 | 247 | } |
| 247 | 248 | |
| @@ -246,9 +247,9 @@ | ||
| 246 | 247 | } |
| 247 | 248 | |
| 248 | 249 | public static function installAddons($addons = []) |
| 249 | 250 | { |
| 250 | - $validAddons = ['fluent-crm', 'fluent-smtp']; | |
| 251 | + $validAddons = ['fluent-crm', 'fluent-smtp', 'fluent-cart']; | |
| 251 | 252 | $validAddons = array_intersect($validAddons, $addons); |
| 252 | 253 | |
| 253 | 254 | if (!$validAddons || !current_user_can('install_plugins')) { |
| 254 | 255 | return; |
| @@ -253,9 +254,9 @@ | ||
| 253 | 254 | if (!$validAddons || !current_user_can('install_plugins')) { |
| 254 | 255 | return; |
| 255 | 256 | } |
| 256 | 257 | |
| 257 | - foreach ($addons as $addon) { | |
| 258 | + foreach ($validAddons as $addon) { | |
| 258 | 259 | self::installPlugin($addon); |
| 259 | 260 | } |
| 260 | 261 | |
| 261 | 262 | return true; |
| @@ -274,16 +275,18 @@ | ||
| 274 | 275 | if (!$userEmail) { |
| 275 | 276 | return; |
| 276 | 277 | } |
| 277 | 278 | |
| 278 | - $url = 'https://fluentcommunity.co/?fluentcrm=1&route=contact&hash=8850223d-c62d-4e6a-8108-b04c7e9e4fdb'; | |
| 279 | + $url = 'https://fluentcommunity.co/discount-deal/?fluentcrm=1&route=contact&hash=8850223d-c62d-4e6a-8108-b04c7e9e4fdb'; | |
| 279 | 280 | |
| 280 | - $response = wp_remote_post($url, [ | |
| 281 | - '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 | |
| 282 | 285 | 'full_name' => $userFullName, |
| 283 | 286 | 'email' => $userEmail, |
| 284 | 287 | 'source' => 'fcom_plugin', |
| 285 | - 'optin_website' => site_url(), | |
| 288 | + 'optin_website' => home_url(), | |
| 286 | 289 | 'share_essential' => Arr::get($settings, 'share_data', 'no') === 'yes' ? 'yes' : 'no', |
| 287 | 290 | ]) |
| 288 | 291 | ]); |
| 289 | 292 | |
| @@ -306,11 +309,15 @@ | ||
| 306 | 309 | 'fluent-crm' => [ |
| 307 | 310 | 'admin_url' => admin_url('admin.php?page=fluentcrm-admin'), |
| 308 | 311 | 'title' => 'Go to FluentCRM Dashboard' |
| 309 | 312 | ], |
| 310 | - 'ninja-smtp' => [ | |
| 313 | + 'fluent-smtp' => [ | |
| 311 | 314 | 'admin_url' => admin_url('options-general.php?page=fluent-mail#/'), |
| 312 | 315 | 'title' => 'Go to FluentSMTP Dashboard' |
| 316 | + ], | |
| 317 | + 'fluent-cart' => [ | |
| 318 | + 'admin_url' => admin_url('admin.php?page=fluent-cart#/'), | |
| 319 | + 'title' => 'Go to FluentCart Dashboard' | |
| 313 | 320 | ] |
| 314 | 321 | ]; |
| 315 | 322 | |
| 316 | 323 | if (!isset($UrlMaps[$pluginSlug]) || (defined('DISALLOW_FILE_MODS') && DISALLOW_FILE_MODS)) { |
| @@ -323,9 +330,9 @@ | ||
| 323 | 330 | return new \WP_Error('plugin_install_error', $exception->getMessage()); |
| 324 | 331 | } |
| 325 | 332 | } |
| 326 | 333 | |
| 327 | - private static function backgroundInstaller($plugin_to_install) | |
| 334 | + public static function backgroundInstaller($plugin_to_install) | |
| 328 | 335 | { |
| 329 | 336 | if (!empty($plugin_to_install['repo-slug'])) { |
| 330 | 337 | require_once ABSPATH . 'wp-admin/includes/file.php'; |
| 331 | 338 | require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; |
| @@ -335,9 +342,9 @@ | ||
| 335 | 342 | WP_Filesystem(); |
| 336 | 343 | |
| 337 | 344 | $skin = new \Automatic_Upgrader_Skin(); |
| 338 | 345 | $upgrader = new \WP_Upgrader($skin); |
| 339 | - $installed_plugins = array_keys(\get_plugins()); | |
| 346 | + $installed_plugins = array_reduce(array_keys(\get_plugins()), array(self::class, 'associate_plugin_file'), array()); | |
| 340 | 347 | $plugin_slug = $plugin_to_install['repo-slug']; |
| 341 | 348 | $plugin_file = isset($plugin_to_install['file']) ? $plugin_to_install['file'] : $plugin_slug . '.php'; |
| 342 | 349 | $installed = false; |
| 343 | 350 | $activate = false; |
| @@ -411,15 +418,12 @@ | ||
| 411 | 418 | throw new \Exception(wp_kses_post($result->get_error_message())); |
| 412 | 419 | } |
| 413 | 420 | |
| 414 | 421 | $activate = true; |
| 415 | - | |
| 416 | - } catch (\Exception $e) { | |
| 417 | - throw new \Exception(esc_html($e->getMessage())); | |
| 422 | + } finally { | |
| 423 | + // Discard feedback. | |
| 424 | + ob_end_clean(); | |
| 418 | 425 | } |
| 419 | - | |
| 420 | - // Discard feedback. | |
| 421 | - ob_end_clean(); | |
| 422 | 426 | } |
| 423 | 427 | |
| 424 | 428 | wp_clean_plugins_cache(); |
| 425 | 429 | |
| @@ -424,17 +428,21 @@ | ||
| 424 | 428 | wp_clean_plugins_cache(); |
| 425 | 429 | |
| 426 | 430 | // Activate this thing. |
| 427 | 431 | if ($activate) { |
| 428 | - try { | |
| 429 | - $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); | |
| 430 | 433 | |
| 431 | - if (is_wp_error($result)) { | |
| 432 | - throw new \Exception(esc_html($result->get_error_message())); | |
| 433 | - } | |
| 434 | - } catch (\Exception $e) { | |
| 435 | - throw new \Exception(esc_html($e->getMessage())); | |
| 434 | + if (is_wp_error($result)) { | |
| 435 | + throw new \Exception(wp_kses_post($result->get_error_message())); | |
| 436 | 436 | } |
| 437 | 437 | } |
| 438 | 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; | |
| 439 | 447 | } |
| 440 | 448 | } |