| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCommunity\App\Http\Controllers; |
| 4 |
|
| 5 |
use FluentCommunity\App\Functions\Utility; |
| 6 |
use FluentCommunity\App\Models\BaseSpace; |
| 7 |
use FluentCommunity\App\Services\AuthenticationService; |
| 8 |
use FluentCommunity\App\Services\CustomSanitizer; |
| 9 |
use FluentCommunity\App\Services\FeedsHelper; |
| 10 |
use FluentCommunity\App\Services\ProfileHelper; |
| 11 |
use FluentCommunity\Modules\Auth\AuthHelper; |
| 12 |
use FluentCommunity\App\Services\Helper; |
| 13 |
use FluentCommunity\App\Services\OnboardingService; |
| 14 |
use FluentCommunity\Framework\Http\Request\Request; |
| 15 |
use FluentCommunity\Framework\Support\Arr; |
| 16 |
|
| 17 |
class AdminController extends Controller |
| 18 |
{ |
| 19 |
public function getGeneralSettings(Request $request) |
| 20 |
{ |
| 21 |
$settings = Helper::generalSettings(false); |
| 22 |
|
| 23 |
$userRoles = wp_roles()->roles; |
| 24 |
|
| 25 |
$formatedRoles = []; |
| 26 |
foreach ($userRoles as $role => $roleData) { |
| 27 |
$formatedRoles[$role] = $roleData['name']; |
| 28 |
} |
| 29 |
|
| 30 |
unset($formatedRoles['administrator']); |
| 31 |
|
| 32 |
$data = [ |
| 33 |
'settings' => $settings, |
| 34 |
'user_roles' => $formatedRoles, |
| 35 |
'users_can_register' => !!get_option('users_can_register'), |
| 36 |
'user_registration_enable_url' => admin_url('options-general.php') |
| 37 |
]; |
| 38 |
return apply_filters('fluent_community/general_settings_api_response', $data, $request->all()); |
| 39 |
} |
| 40 |
|
| 41 |
public function saveGeneralSettings(Request $request) |
| 42 |
{ |
| 43 |
$inputs = $request->get('settings', []); |
| 44 |
$settings = Helper::generalSettings(false); |
| 45 |
$inputs = Arr::only($inputs, array_keys($settings)); |
| 46 |
|
| 47 |
$settings['logo'] = Arr::get($inputs, 'logo', ''); |
| 48 |
$settings['white_logo'] = Arr::get($inputs, 'white_logo', ''); |
| 49 |
$settings['featured_image'] = Arr::get($inputs, 'featured_image', ''); |
| 50 |
|
| 51 |
if (!empty($settings['logo'])) { |
| 52 |
$settings['logo'] = sanitize_url($settings['logo']); |
| 53 |
} |
| 54 |
|
| 55 |
if (!empty($settings['white_logo'])) { |
| 56 |
$settings['white_logo'] = sanitize_url($settings['white_logo']); |
| 57 |
} |
| 58 |
|
| 59 |
if (!empty($settings['featured_image'])) { |
| 60 |
$settings['featured_image'] = sanitize_url($settings['featured_image']); |
| 61 |
} |
| 62 |
|
| 63 |
if (!empty($settings['site_title'])) { |
| 64 |
$settings['site_title'] = sanitize_text_field(Arr::get($inputs, 'site_title', '')); |
| 65 |
} |
| 66 |
|
| 67 |
$settings['disable_global_posts'] = sanitize_text_field(Arr::get($inputs, 'disable_global_posts', 'no')); |
| 68 |
$settings['access'] = Arr::get($inputs, 'access', []); |
| 69 |
$settings['auth_content'] = wp_kses_post(Arr::get($inputs, 'auth_content', '')); |
| 70 |
$settings['auth_redirect'] = sanitize_url(Arr::get($inputs, 'auth_redirect', '')); |
| 71 |
$settings['restricted_role_content'] = wp_kses_post(Arr::get($inputs, 'restricted_role_content', '')); |
| 72 |
$settings['logo_permalink'] = sanitize_url(Arr::get($inputs, 'logo_permalink', '')); |
| 73 |
$settings['logo_permalink_type'] = sanitize_text_field(Arr::get($inputs, 'logo_permalink_type', 'default')); |
| 74 |
$settings['auth_url'] = sanitize_url(Arr::get($inputs, 'auth_url', '')); |
| 75 |
$media = Helper::getMediaFromUrl($settings['logo']); |
| 76 |
$whiteMedia = Helper::getMediaFromUrl($settings['white_logo']); |
| 77 |
$featuredMedia = Helper::getMediaFromUrl($settings['featured_image']); |
| 78 |
$settings['cutsom_auth_url'] = sanitize_url(Arr::get($inputs, 'cutsom_auth_url', '')); |
| 79 |
$settings['auth_form_type'] = sanitize_text_field(Arr::get($inputs, 'auth_form_type', '')); |
| 80 |
$settings['explicit_registration'] = sanitize_text_field(Arr::get($inputs, 'explicit_registration', 'no')); |
| 81 |
|
| 82 |
$isCustomSignupPage = $settings['auth_form_type'] === 'default' && Arr::get($inputs, 'use_custom_signup_page', 'no') == 'yes'; |
| 83 |
if (!$isCustomSignupPage) { |
| 84 |
$settings['custom_signup_url'] = ''; |
| 85 |
$settings['use_custom_signup_page'] = 'no'; |
| 86 |
} else { |
| 87 |
$settings['use_custom_signup_page'] = 'yes'; |
| 88 |
|
| 89 |
$url = Arr::get($inputs, 'custom_signup_url', ''); |
| 90 |
|
| 91 |
if (!$url || !filter_var($url, FILTER_VALIDATE_URL)) { |
| 92 |
return $this->sendError([ |
| 93 |
'message' => __('Please provide a valid signup URL', 'fluent-community') |
| 94 |
]); |
| 95 |
} |
| 96 |
$settings['custom_signup_url'] = $url; |
| 97 |
} |
| 98 |
|
| 99 |
if ($media) { |
| 100 |
$settings['logo'] = $media->public_url; |
| 101 |
$media->update([ |
| 102 |
'is_active' => true, |
| 103 |
'user_id' => get_current_user_id(), |
| 104 |
'object_source' => 'general' |
| 105 |
]); |
| 106 |
} |
| 107 |
|
| 108 |
if ($whiteMedia) { |
| 109 |
$settings['white_logo'] = $whiteMedia->public_url; |
| 110 |
$whiteMedia->update([ |
| 111 |
'is_active' => true, |
| 112 |
'user_id' => get_current_user_id(), |
| 113 |
'object_source' => 'general' |
| 114 |
]); |
| 115 |
} |
| 116 |
|
| 117 |
if ($featuredMedia) { |
| 118 |
$settings['featured_image'] = $featuredMedia->public_url; |
| 119 |
$featuredMedia->update([ |
| 120 |
'is_active' => true, |
| 121 |
'user_id' => get_current_user_id(), |
| 122 |
'object_source' => 'general' |
| 123 |
]); |
| 124 |
} |
| 125 |
|
| 126 |
$slugChanged = false; |
| 127 |
$newSlug = sanitize_title($inputs['slug'] ?? ''); |
| 128 |
if ($newSlug && $settings['slug'] != $newSlug && !defined('FLUENT_COMMUNITY_PORTAL_SLUG')) { |
| 129 |
$settings['slug'] = $newSlug; |
| 130 |
$slugChanged = true; |
| 131 |
} |
| 132 |
|
| 133 |
update_option('fluent_community_settings', $settings); |
| 134 |
|
| 135 |
$redirectUrl = ''; |
| 136 |
|
| 137 |
if ($slugChanged) { |
| 138 |
// flush rewrite rules |
| 139 |
flush_rewrite_rules(true); |
| 140 |
Helper::generalSettings(false); |
| 141 |
$redirectUrl = Helper::baseUrl('admin/settings/general'); |
| 142 |
} |
| 143 |
|
| 144 |
return [ |
| 145 |
'message' => __('Settings have been saved successfully.', 'fluent-community'), |
| 146 |
'redirect_url' => $redirectUrl |
| 147 |
]; |
| 148 |
} |
| 149 |
|
| 150 |
public function getEmailSettings(Request $request) |
| 151 |
{ |
| 152 |
$emailSettings = Utility::getEmailNotificationSettings(); |
| 153 |
$globalSettings = Helper::generalSettings(false); |
| 154 |
if (empty($emailSettings['logo'])) { |
| 155 |
$emailSettings['global_logo'] = $globalSettings['logo']; |
| 156 |
} |
| 157 |
|
| 158 |
$data = [ |
| 159 |
'email_settings' => $emailSettings |
| 160 |
]; |
| 161 |
return apply_filters('fluent_community/email_settings_api_response', $data, $request->all()); |
| 162 |
} |
| 163 |
|
| 164 |
public function saveEmailSettings(Request $request) |
| 165 |
{ |
| 166 |
$prevSettings = Utility::getEmailNotificationSettings(); |
| 167 |
$newSettings = $request->get('email_settings', []); |
| 168 |
|
| 169 |
$logo = Arr::get($newSettings, 'logo', ''); |
| 170 |
|
| 171 |
if ($logo) { |
| 172 |
$logoMedia = Helper::getMediaFromUrl($logo); |
| 173 |
if ($logoMedia) { |
| 174 |
$newSettings['logo'] = $logoMedia->public_url; |
| 175 |
$logoMedia->update([ |
| 176 |
'is_active' => true, |
| 177 |
'user_id' => get_current_user_id(), |
| 178 |
'object_source' => 'general' |
| 179 |
]); |
| 180 |
} |
| 181 |
} |
| 182 |
|
| 183 |
$newSettings = wp_parse_args($newSettings, $prevSettings); |
| 184 |
$newSettings = CustomSanitizer::santizeEmailSettings($newSettings); |
| 185 |
|
| 186 |
Utility::updateOption('global_email_settings', $newSettings); |
| 187 |
|
| 188 |
/* |
| 189 |
* We are unscheduling all digest schedules if the settings has been changed or disabled |
| 190 |
*/ |
| 191 |
$isScheduleChanged = ($newSettings['digest_mail_day'] != $prevSettings['digest_mail_day']) || ($newSettings['daily_digest_time'] != $prevSettings['daily_digest_time']); |
| 192 |
if ($isScheduleChanged) { |
| 193 |
if (as_next_scheduled_action('fluent_community_send_daily_digest_init')) { |
| 194 |
as_unschedule_all_actions('fluent_community_send_daily_digest_init', [], 'fluent-community'); |
| 195 |
} |
| 196 |
} |
| 197 |
|
| 198 |
return [ |
| 199 |
'email_settings' => $newSettings, |
| 200 |
'message' => __('Email notification settings have been updated', 'fluent-community') |
| 201 |
]; |
| 202 |
} |
| 203 |
|
| 204 |
public function getStorageSettings(Request $request) |
| 205 |
{ |
| 206 |
if (!defined('FLUENT_COMMUNITY_PRO')) { |
| 207 |
$config = [ |
| 208 |
'driver' => 'local' |
| 209 |
]; |
| 210 |
} else { |
| 211 |
$config = \FluentCommunityPro\App\Modules\CloudStorage\StorageHelper::getConfig('view'); |
| 212 |
} |
| 213 |
|
| 214 |
return apply_filters('fluent_community/storage_settings_response', [ |
| 215 |
'config' => $config |
| 216 |
], $request->all()); |
| 217 |
} |
| 218 |
|
| 219 |
public function updateStorageSettings(Request $request) |
| 220 |
{ |
| 221 |
if (!defined('FLUENT_COMMUNITY_PRO')) { |
| 222 |
return $this->sendError([ |
| 223 |
'message' => __('Sorry, you cannot update this config. Please activate pro', 'fluent-community') |
| 224 |
]); |
| 225 |
} |
| 226 |
|
| 227 |
if (defined('FLUENT_COMMUNITY_CLOUD_STORAGE') && FLUENT_COMMUNITY_CLOUD_STORAGE) { |
| 228 |
return $this->sendError([ |
| 229 |
'message' => __('You cannot update the storage settings as it is defined in the config file', 'fluent-community') |
| 230 |
]); |
| 231 |
} |
| 232 |
|
| 233 |
$config = $request->get('config', []); |
| 234 |
|
| 235 |
$driver = Arr::get($config, 'driver', 'local'); |
| 236 |
|
| 237 |
$validation = [ |
| 238 |
'driver' => 'required' |
| 239 |
]; |
| 240 |
|
| 241 |
$isRemote = in_array($driver, ['amazon_s3', 'bunny_cdn', 'cloudflare_r2']); |
| 242 |
|
| 243 |
if ($driver == 'cloudflare_r2') { |
| 244 |
$validation = [ |
| 245 |
'driver' => 'required', |
| 246 |
'access_key' => 'required', |
| 247 |
'secret_key' => 'required', |
| 248 |
'public_url' => 'required|url', |
| 249 |
'endpoint_url' => 'required|url', |
| 250 |
]; |
| 251 |
} else if ($driver == 'amazon_s3') { |
| 252 |
$validation = [ |
| 253 |
'driver' => 'required', |
| 254 |
'access_key' => 'required', |
| 255 |
'secret_key' => 'required', |
| 256 |
'bucket' => 'required' |
| 257 |
]; |
| 258 |
} else if ($driver == 'bunny_cdn') { |
| 259 |
$validation = [ |
| 260 |
'driver' => 'required', |
| 261 |
'access_key' => 'required', |
| 262 |
's3_endpoint' => 'required', |
| 263 |
'bucket' => 'required', |
| 264 |
'public_url' => 'required|url' |
| 265 |
]; |
| 266 |
} |
| 267 |
|
| 268 |
$this->validate($config, $validation); |
| 269 |
|
| 270 |
if ($isRemote) { |
| 271 |
$previousConfig = \FluentCommunityPro\App\Modules\CloudStorage\StorageHelper::getConfig(); |
| 272 |
if ($config['access_key'] == 'FCOM_ENCRYPTED_DATA_KEY') { |
| 273 |
$config['access_key'] = Arr::get($previousConfig, 'access_key'); |
| 274 |
} |
| 275 |
|
| 276 |
if ($config['secret_key'] == 'FCOM_ENCRYPTED_DATA_KEY') { |
| 277 |
$config['secret_key'] = Arr::get($previousConfig, 'secret_key'); |
| 278 |
} |
| 279 |
|
| 280 |
$driver = (new \FluentCommunityPro\App\Modules\CloudStorage\CloudStorageModule)->getConnectionDriver($config); |
| 281 |
|
| 282 |
if (!$driver) { |
| 283 |
return $this->sendError([ |
| 284 |
'message' => __('Could not connect to the remote storage service. Please check your credentials', 'fluent-community') |
| 285 |
]); |
| 286 |
} |
| 287 |
|
| 288 |
$test = $driver->testConnection(); |
| 289 |
if (!$test || is_wp_error($test)) { |
| 290 |
$errorMessage = is_wp_error($test) ? $test->get_error_message() : 'Unknown Error'; |
| 291 |
return $this->sendError([ |
| 292 |
'message' => __('Could not connect to the remote storage service. Error: ', 'fluent-community') . $errorMessage |
| 293 |
]); |
| 294 |
} |
| 295 |
} |
| 296 |
|
| 297 |
$config = Arr::only($config, [ |
| 298 |
'driver', |
| 299 |
'access_key', |
| 300 |
'secret_key', |
| 301 |
'bucket', |
| 302 |
'public_url', |
| 303 |
'endpoint_url', |
| 304 |
'account_id', |
| 305 |
'sub_folder', |
| 306 |
's3_endpoint' |
| 307 |
]); |
| 308 |
|
| 309 |
if ($config['driver'] == 'local') { |
| 310 |
$config = [ |
| 311 |
'driver' => 'local' |
| 312 |
]; |
| 313 |
|
| 314 |
$featureConfig = Utility::getFeaturesConfig(); |
| 315 |
$featureConfig['cloud_storage'] = 'no'; |
| 316 |
Utility::updateOption('fluent_community_features', $featureConfig); |
| 317 |
} else { |
| 318 |
$featureConfig = Utility::getFeaturesConfig(); |
| 319 |
$featureConfig['cloud_storage'] = 'yes'; |
| 320 |
Utility::updateOption('fluent_community_features', $featureConfig); |
| 321 |
} |
| 322 |
|
| 323 |
$config = array_filter($config); |
| 324 |
\FluentCommunityPro\App\Modules\CloudStorage\StorageHelper::updateConfig($config); |
| 325 |
|
| 326 |
return [ |
| 327 |
'message' => __('Storage settings have been updated successfully', 'fluent-community') |
| 328 |
]; |
| 329 |
} |
| 330 |
|
| 331 |
public function getWelcomeBannerSettings(Request $request) |
| 332 |
{ |
| 333 |
$settings = apply_filters('fluent_community/get_welcome_banner_settings', Helper::getWelcomeBannerSettings(), $request->all()); |
| 334 |
|
| 335 |
return [ |
| 336 |
'settings' => $settings |
| 337 |
]; |
| 338 |
} |
| 339 |
|
| 340 |
public function updateWelcomeBannerSettings(Request $request) |
| 341 |
{ |
| 342 |
$settings = $request->get('settings', []); |
| 343 |
|
| 344 |
$settings = CustomSanitizer::sanitizeWelcomeBannerSettings($settings); |
| 345 |
|
| 346 |
if (Arr::get($settings, 'login.enabled') == 'yes') { |
| 347 |
$settings['login']['description_rendered'] = wp_kses_post(FeedsHelper::mdToHtml(Arr::get($settings, 'login.description'))); |
| 348 |
} |
| 349 |
|
| 350 |
if (Arr::get($settings, 'logout.enabled') == 'yes') { |
| 351 |
$settings['logout']['description_rendered'] = wp_kses_post(FeedsHelper::mdToHtml(Arr::get($settings, 'logout.description'))); |
| 352 |
if (Arr::get($settings, 'logout.buttonLabel') && Arr::get($settings, 'logout.useCustomUrl') != 'yes') { |
| 353 |
$settings['logout']['buttonLink'] = Helper::getAuthUrl(); |
| 354 |
} |
| 355 |
} |
| 356 |
|
| 357 |
$settings = apply_filters('fluent_community/update_welcome_banner_settings', $settings); |
| 358 |
|
| 359 |
Utility::updateOption('welcome_banner_settings', $settings); |
| 360 |
|
| 361 |
Utility::setCache('welcome_banner_settings', $settings, WEEK_IN_SECONDS); |
| 362 |
|
| 363 |
return [ |
| 364 |
'message' => __('Welcome banner settings have been updated successfully', 'fluent-community'), |
| 365 |
'settings' => $settings |
| 366 |
]; |
| 367 |
} |
| 368 |
|
| 369 |
public function getAuthSettings() |
| 370 |
{ |
| 371 |
$settings = AuthenticationService::getAuthSettings(); |
| 372 |
|
| 373 |
$settings['login']['form']['fields'] = AuthHelper::getLoginFormFields(); |
| 374 |
$settings['signup']['form']['fields'] = AuthHelper::getFormFields(); |
| 375 |
|
| 376 |
$settings = apply_filters('fluent_community/get_auth_settings', $settings); |
| 377 |
|
| 378 |
return [ |
| 379 |
'settings' => $settings |
| 380 |
]; |
| 381 |
} |
| 382 |
|
| 383 |
public function getOnBoardingSettings() |
| 384 |
{ |
| 385 |
$settings = Helper::generalSettings(); |
| 386 |
|
| 387 |
$currentUser = get_user_by('ID', get_current_user_id()); |
| 388 |
|
| 389 |
$settings['has_fluentcrm'] = defined('FLUENTCRM') ? 'yes' : 'no'; |
| 390 |
$settings['has_fluentsmtp'] = defined('FLUENTMAIL_PLUGIN_FILE') ? 'yes' : 'no'; |
| 391 |
$settings['has_fluentcart'] = defined('FLUENTCART_VERSION') ? 'yes' : 'no'; |
| 392 |
$settings['template'] = ''; |
| 393 |
$settings['install_fluentcrm'] = 'yes'; |
| 394 |
$settings['install_fluentsmtp'] = 'yes'; |
| 395 |
$settings['install_fluentcart'] = 'yes'; |
| 396 |
$settings['subscribe_to_newsletter'] = 'yes'; |
| 397 |
$settings['share_data'] = 'no'; |
| 398 |
if ($currentUser) { |
| 399 |
$settings['user_full_name'] = $currentUser->first_name ? $currentUser->first_name . ' ' . $currentUser->last_name : $currentUser->display_name; |
| 400 |
$settings['user_email_address'] = $currentUser->user_email; |
| 401 |
} else { |
| 402 |
$settings['user_full_name'] = ''; |
| 403 |
$settings['user_email_address'] = ''; |
| 404 |
} |
| 405 |
|
| 406 |
$data = [ |
| 407 |
'settings' => $settings |
| 408 |
]; |
| 409 |
return apply_filters('fluent_community/onboarding_settings_api_response', $data, $this->request->all()); |
| 410 |
} |
| 411 |
|
| 412 |
|
| 413 |
public function saveOnBoardingSettings(Request $request) |
| 414 |
{ |
| 415 |
$inputs = $request->get('settings', []); |
| 416 |
$settings = Helper::generalSettings(); |
| 417 |
|
| 418 |
if (Arr::get($inputs, 'site_title')) { |
| 419 |
$settings['site_title'] = sanitize_text_field(Arr::get($inputs, 'site_title')); |
| 420 |
} |
| 421 |
|
| 422 |
$logo = Arr::get($inputs, 'logo'); |
| 423 |
|
| 424 |
if ($logo) { |
| 425 |
$media = Helper::getMediaFromUrl($logo); |
| 426 |
if ($media) { |
| 427 |
$settings['logo'] = $media->public_url; |
| 428 |
$media->update([ |
| 429 |
'is_active' => true, |
| 430 |
'user_id' => get_current_user_id(), |
| 431 |
'object_source' => 'onboarding' |
| 432 |
]); |
| 433 |
} |
| 434 |
} |
| 435 |
|
| 436 |
if (Arr::get($inputs, 'slug') && empty($settings['is_slug_defined'])) { |
| 437 |
$settings['slug'] = sanitize_title(Arr::get($inputs, 'slug')); |
| 438 |
} |
| 439 |
update_option('fluent_community_settings', $settings, true); |
| 440 |
|
| 441 |
// Email Subscription Settings |
| 442 |
$subscriptionSettings = array_filter([ |
| 443 |
'user_id' => get_current_user_id(), |
| 444 |
'subscribe_to_newsletter' => sanitize_text_field(Arr::get($inputs, 'subscribe_to_newsletter', 'no')), |
| 445 |
'share_data' => sanitize_text_field(Arr::get($inputs, 'share_data', 'no')), |
| 446 |
'user_full_name' => sanitize_text_field(Arr::get($inputs, 'user_full_name', '')), |
| 447 |
'user_email_address' => sanitize_email(Arr::get($inputs, 'user_email_address', '')) |
| 448 |
]); |
| 449 |
|
| 450 |
Utility::updateOption('onboarding_sub_settings', $subscriptionSettings); |
| 451 |
OnboardingService::maybeCreateSpaceTemplates(Arr::get($inputs, 'template')); |
| 452 |
|
| 453 |
$installableAddons = array_keys(array_filter([ |
| 454 |
'fluent-crm' => Arr::get($inputs, 'install_fluentcrm', 'no') == 'yes', |
| 455 |
'fluent-smtp' => Arr::get($inputs, 'install_fluentsmtp', 'no') == 'yes', |
| 456 |
'fluent-cart' => Arr::get($inputs, 'install_fluentcart', 'no') == 'yes', |
| 457 |
])); |
| 458 |
|
| 459 |
// Install Plugins which are checked |
| 460 |
OnboardingService::installAddons($installableAddons); |
| 461 |
|
| 462 |
// Maybe Optin User to Newsletter |
| 463 |
OnboardingService::maybeOptinUserToNewsletter($subscriptionSettings); |
| 464 |
|
| 465 |
// flash the permalinks |
| 466 |
flush_rewrite_rules(true); |
| 467 |
|
| 468 |
return [ |
| 469 |
'message' => __('Onboarding settings have been updated.', 'fluent-community') |
| 470 |
]; |
| 471 |
} |
| 472 |
|
| 473 |
public function changePortalSlug(Request $request) |
| 474 |
{ |
| 475 |
$newSlug = sanitize_title($request->get('new_slug', '')); |
| 476 |
|
| 477 |
if (!$newSlug) { |
| 478 |
return $this->sendError([ |
| 479 |
'message' => __('Slug cannot be empty', 'fluent-community') |
| 480 |
]); |
| 481 |
} |
| 482 |
|
| 483 |
if (defined('FLUENT_COMMUNITY_PORTAL_SLUG')) { |
| 484 |
return $this->sendError([ |
| 485 |
'message' => __('You cannot change the slug as it is defined in the config file', 'fluent-community') |
| 486 |
]); |
| 487 |
} |
| 488 |
|
| 489 |
$settings = Helper::generalSettings(); |
| 490 |
|
| 491 |
if ($settings['slug'] != $newSlug) { |
| 492 |
$settings['slug'] = $newSlug; |
| 493 |
|
| 494 |
update_option('fluent_community_settings', $settings); |
| 495 |
flush_rewrite_rules(true); |
| 496 |
|
| 497 |
$slug = $settings['slug']; |
| 498 |
add_rewrite_rule('^' . $slug . '/?$', 'index.php?fcom_route=portal_home', 'top'); // For /hooks |
| 499 |
add_rewrite_rule('^' . $slug . '/(.+)/?', 'index.php?fcom_route=$matches[1]', 'top'); |
| 500 |
// flush rewrite rules |
| 501 |
flush_rewrite_rules(true); |
| 502 |
|
| 503 |
delete_option('rewrite_rules'); |
| 504 |
} |
| 505 |
|
| 506 |
return [ |
| 507 |
'message' => __('Slug has been changed successfully', 'fluent-community') |
| 508 |
]; |
| 509 |
} |
| 510 |
|
| 511 |
public function getProfileLinkProviders(Request $request) |
| 512 |
{ |
| 513 |
$data = [ |
| 514 |
'providers' => ProfileHelper::socialLinkProviders() |
| 515 |
]; |
| 516 |
return apply_filters('fluent_community/profile_link_providers_api_response', $data, $request->all()); |
| 517 |
} |
| 518 |
|
| 519 |
public function updateProfileLinkProviders(Request $request) |
| 520 |
{ |
| 521 |
$providerKeys = array_keys(ProfileHelper::socialLinkProviders()); |
| 522 |
$config = $request->get('configs', []); |
| 523 |
|
| 524 |
$config = array_filter($config, function ($value) use ($providerKeys) { |
| 525 |
return in_array($value, $providerKeys); |
| 526 |
}); |
| 527 |
|
| 528 |
do_action('fluent_community/update_profile_link_providers', $config); |
| 529 |
|
| 530 |
return [ |
| 531 |
'message' => __('Profile link providers have been updated successfully', 'fluent-community'), |
| 532 |
]; |
| 533 |
} |
| 534 |
|
| 535 |
public function getAllSpaceCourses(Request $request) |
| 536 |
{ |
| 537 |
$data = [ |
| 538 |
'all_spaces' => BaseSpace::query()->withoutGlobalScopes() |
| 539 |
->whereIn('type', ['community', 'course']) |
| 540 |
->orderBy('serial', 'ASC')->get() |
| 541 |
]; |
| 542 |
return apply_filters('fluent_community/all_space_courses_api_response', $data, $request->all()); |
| 543 |
} |
| 544 |
|
| 545 |
} |
| 546 |
|