PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.10.0
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.10.0
2.10.0 2.10.01 2.9.1 2.9.0 2.8.1 2.8.0 2.7.7 2.7.5 2.7.0 2.6.01 2.6.0 2.5.0 2.4.01 trunk 1.0.90 1.0.91 1.0.92 1.0.93 1.0.94 1.0.95 1.0.96 1.0.97 1.0.98 1.0.99 1.1.0 All 77 releases
← All changes | app/Http/Controllers/SettingController.php +47 -13 2.9.12.10.0 View file →
@@ -283,14 +283,8 @@
283 283 }
284 284
285 285 public function installPlugin(Request $request)
286 286 {
287 - if (!current_user_can('install_plugins')) {
288 - return $this->sendError([
289 - 'message' => __('You do not have permission to install plugins', 'fluent-community')
290 - ]);
291 - }
292 -
293 287 $pluginSlug = $request->get('plugin');
294 288
295 289 $addons = $this->getAddons();
296 290
@@ -299,8 +293,39 @@
299 293 }
300 294
301 295 $details = $addons[$pluginSlug];
302 296
297 + $pluginFile = $pluginSlug . '/' . $pluginSlug . '.php';
298 +
299 + // Already on disk but deactivated: that is an activation, so it answers to
300 + // activate_plugins and needs no download.
301 + if (!$details['is_repo'] && $this->isPluginInstalled($pluginFile)) {
302 + if (!current_user_can('activate_plugins')) {
303 + return $this->sendError(['message' => __('You do not have permission to activate plugins', 'fluent-community')]);
304 + }
305 +
306 + require_once ABSPATH . 'wp-admin/includes/plugin.php';
307 +
308 + if (!is_plugin_active($pluginFile)) {
309 + $activated = activate_plugin($pluginFile);
310 +
311 + if (is_wp_error($activated)) {
312 + return $this->sendError(['message' => wp_kses_post($activated->get_error_message())]);
313 + }
314 + }
315 +
316 + return [
317 + 'message' => __('Plugin has been activated Successfully', 'fluent-community'),
318 + 'is_installed' => true
319 + ];
320 + }
321 +
322 + if (!current_user_can('install_plugins')) {
323 + return $this->sendError([
324 + 'message' => __('You do not have permission to install plugins', 'fluent-community')
325 + ]);
326 + }
327 +
303 328 if ($details['is_repo']) {
304 329 $plugin = [
305 330 'name' => $details['title'],
306 331 'repo-slug' => $pluginSlug,
@@ -311,13 +336,15 @@
311 336 } catch (\Exception $e) {
312 337 return $this->sendError(['message' => $e->getMessage()]);
313 338 }
314 339 } else {
340 + $installHook = '';
341 +
315 342 if ($pluginSlug == 'fluent-messaging') {
316 343 if (!defined('FLUENT_COMMUNITY_PRO')) {
317 344 return $this->sendError(['message' => __('FluentMessaging is a Pro Plugin. Please install FluentCommunity Pro first.', 'fluent-community')]);
318 345 }
319 - do_action('fluent_community/install_messaging_plugin');
346 + $installHook = 'fluent_community/install_messaging_plugin';
320 347 } else if ($pluginSlug == 'fluent-player') {
321 348
322 349 if (!defined('FLUENT_COMMUNITY_PRO')) {
323 350 return $this->sendError(['message' => __('FluentPlayer requires the pro version of FluentCommunity. Please install FluentCommunity Pro first.', 'fluent-community')]);
@@ -322,15 +349,22 @@
322 349 if (!defined('FLUENT_COMMUNITY_PRO')) {
323 350 return $this->sendError(['message' => __('FluentPlayer requires the pro version of FluentCommunity. Please install FluentCommunity Pro first.', 'fluent-community')]);
324 351 }
325 352
326 - do_action('fluent_community/install_fluent_player_plugin');
353 + $installHook = 'fluent_community/install_fluent_player_plugin';
327 354 } else if ($pluginSlug == 'fluent-notify') {
328 - try {
329 - do_action('fluent_community/install_fluent_notify_plugin');
330 - } catch (\Exception $e) {
331 - return $this->sendError(['message' => $e->getMessage()]);
332 - }
355 + $installHook = 'fluent_community/install_fluent_notify_plugin';
356 + }
357 +
358 + if (!$installHook || !has_action($installHook)) {
359 + return $this->sendError(['message' => __('This plugin can not be installed from here. Please install it manually.', 'fluent-community')]);
360 + }
361 +
362 + try {
363 + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound -- every assigned value is a literal fluent_community/ prefixed hook, guarded above
364 + do_action($installHook);
365 + } catch (\Exception $e) {
366 + return $this->sendError(['message' => $e->getMessage()]);
333 367 }
334 368 }
335 369
336 370 return [