PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.1
Booking for Appointments and Events Calendar – Amelia v2.4.1
2.4.5 2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / src / Infrastructure / WP / SettingsService / SettingsStorage.php
ameliabooking / src / Infrastructure / WP / SettingsService Last commit date
SettingsStorage.php 2 months ago
SettingsStorage.php
986 lines
1 <?php
2
3 namespace AmeliaBooking\Infrastructure\WP\SettingsService;
4
5 use AmeliaBooking\Application\Services\Location\AbstractCurrentLocation;
6 use AmeliaBooking\Domain\Services\DateTime\DateTimeService;
7 use AmeliaBooking\Domain\Services\Settings\SettingsStorageInterface;
8 use AmeliaBooking\Infrastructure\Licence;
9 use AmeliaBooking\Plugin;
10
11 /**
12 * Class SettingsStorage
13 *
14 * @package AmeliaBooking\Infrastructure\WP\SettingsService
15 */
16 class SettingsStorage implements SettingsStorageInterface
17 {
18 /** @var array|mixed */
19 private $settingsCache;
20
21 /** @var AbstractCurrentLocation */
22 private $locationService;
23
24 private static $wpSettings = [
25 'dateFormat' => 'date_format',
26 'timeFormat' => 'time_format',
27 'startOfWeek' => 'start_of_week',
28 'timeZoneString' => 'timezone_string',
29 'gmtOffset' => 'gmt_offset'
30 ];
31
32 public function __construct()
33 {
34 if (!defined('AMELIA_LOCALE')) {
35 define('AMELIA_LOCALE', get_user_locale());
36 }
37
38 $this->locationService = Licence\ApplicationService::getCurrentLocationService();
39
40 $this->settingsCache = self::getSavedSettings();
41
42 Licence\DataModifier::modifySettings($this->settingsCache);
43
44 foreach (self::$wpSettings as $ameliaSetting => $wpSetting) {
45 $this->settingsCache['wordpress'][$ameliaSetting] = get_option($wpSetting);
46 }
47
48 $this->settingsCache['wordpress']['locale'] = AMELIA_LOCALE;
49
50 DateTimeService::setTimeZone($this->getAllSettings());
51 }
52
53 /**
54 * @return array
55 */
56 private function getSavedSettings()
57 {
58 return json_decode(get_option('amelia_settings'), true);
59 }
60
61 /**
62 * @param $settingCategoryKey
63 * @param $settingKey
64 *
65 * @return mixed
66 */
67 public function getSetting($settingCategoryKey, $settingKey)
68 {
69 return $this->settingsCache[$settingCategoryKey][$settingKey] ?? null;
70 }
71
72 /**
73 * @param $settingCategoryKey
74 *
75 * @return mixed
76 */
77 public function getCategorySettings($settingCategoryKey)
78 {
79 return $this->settingsCache[$settingCategoryKey] ?? null;
80 }
81
82 /**
83 * @return array|mixed|null
84 */
85 public function getAllSettings()
86 {
87 $settings = [];
88
89 if (null !== $this->settingsCache) {
90 foreach ((array)$this->settingsCache as $settingsCategoryName => $settingsCategory) {
91 if ($settingsCategoryName !== 'daysOff') {
92 foreach ((array)$settingsCategory as $settingName => $settingValue) {
93 $settings[$settingName] = $settingValue;
94 }
95 }
96 }
97
98 return $settings;
99 }
100
101 return null;
102 }
103
104 /**
105 * @return array|mixed|null
106 */
107 public function getAllSettingsCategorized()
108 {
109 return $this->settingsCache ?? null;
110 }
111
112 /**
113 * Return settings for frontend
114 *
115 * @return array|mixed
116 */
117 public function getFrontendSettings()
118 {
119 $phoneCountryCode = $this->getSetting('general', 'phoneDefaultCountryCode');
120 $ipLocateApyKey = $this->getSetting('general', 'ipLocateApiKey');
121
122 $capabilities = [];
123 $additionalCapabilities = [];
124 if (is_admin()) {
125 $currentScreenId = get_current_screen()->id;
126 $currentScreen = substr($currentScreenId, strrpos($currentScreenId, '-') + 1);
127
128 $capabilities = [
129 'canRead' => current_user_can('amelia_read_' . $currentScreen),
130 'canReadOthers' => current_user_can('amelia_read_others_' . $currentScreen),
131 'canWrite' => current_user_can('amelia_write_' . $currentScreen),
132 'canWriteOthers' => current_user_can('amelia_write_others_' . $currentScreen),
133 'canDelete' => current_user_can('amelia_delete_' . $currentScreen),
134 'canWriteStatus' => current_user_can('amelia_write_status_' . $currentScreen),
135 ];
136
137 $additionalCapabilities = [
138 'canWriteCustomers' => current_user_can('amelia_write_customers'),
139 ];
140 }
141
142 $wpUser = wp_get_current_user();
143
144 $userType = 'customer';
145
146 if (in_array('administrator', $wpUser->roles, true) || is_super_admin($wpUser->ID)) {
147 $userType = 'admin';
148 } elseif (in_array('wpamelia-manager', $wpUser->roles, true)) {
149 $userType = 'manager';
150 } elseif (in_array('wpamelia-provider', $wpUser->roles, true)) {
151 $userType = 'provider';
152 }
153
154 return [
155 'capabilities' => $capabilities,
156 'additionalCapabilities' => $additionalCapabilities,
157 'daysOff' => $this->getCategorySettings('daysOff'),
158 'general' => [
159 'itemsPerPage' => $this->getSetting('general', 'itemsPerPage'),
160 'appointmentsPerPage' => $this->getSetting('general', 'appointmentsPerPage'),
161 'eventsPerPage' => $this->getSetting('general', 'eventsPerPage'),
162 'servicesPerPage' => $this->getSetting('general', 'servicesPerPage'),
163 'customersFilterLimit' => $this->getSetting('general', 'customersFilterLimit'),
164 'eventsFilterLimit' => $this->getSetting(
165 'general',
166 'eventsFilterLimit'
167 ) ?: 1000,
168 'calendarEmployeesPreselected' => $this->getSetting(
169 'general',
170 'calendarEmployeesPreselected'
171 ),
172 'phoneDefaultCountryCode' => $phoneCountryCode === 'auto' ?
173 $this->locationService->getCurrentLocationCountryIso($ipLocateApyKey) : $phoneCountryCode,
174 'timeSlotLength' => $this->getSetting('general', 'timeSlotLength'),
175 'serviceDurationAsSlot' => $this->getSetting('general', 'serviceDurationAsSlot'),
176 'defaultAppointmentStatus' => $this->getSetting('general', 'defaultAppointmentStatus'),
177 'gMapApiKey' => !empty($this->getSetting('general', 'gMapApiKey')),
178 'googleClientId' => $this->getSetting('googleCalendar', 'clientID'),
179 'googleAccessToken' => !empty($this->getSetting('googleCalendar', 'accessToken')),
180 'googleAccountData' => $this->getSetting('googleCalendar', 'googleAccountData'),
181 'outlookAccountData' => $this->getSetting('outlookCalendar', 'outlookAccountData'),
182 'addToCalendar' => $this->getSetting('general', 'addToCalendar'),
183 'requiredPhoneNumberField' => $this->getSetting('general', 'requiredPhoneNumberField'),
184 'requiredEmailField' => $this->getSetting('general', 'requiredEmailField'),
185 'numberOfDaysAvailableForBooking' => $this->getSetting(
186 'general',
187 'numberOfDaysAvailableForBooking'
188 ),
189 'minimumTimeRequirementPriorToBooking' =>
190 $this->getSetting('general', 'minimumTimeRequirementPriorToBooking'),
191 'minimumTimeRequirementPriorToCanceling' =>
192 $this->getSetting('general', 'minimumTimeRequirementPriorToCanceling'),
193 'minimumTimeRequirementPriorToRescheduling' =>
194 $this->getSetting('general', 'minimumTimeRequirementPriorToRescheduling'),
195 'showClientTimeZone' => $this->getSetting(
196 'general',
197 'showClientTimeZone'
198 ),
199 'redirectUrlAfterAppointment' => $this->getSetting(
200 'general',
201 'redirectUrlAfterAppointment'
202 ),
203 'customFieldsUploadsPath' => $this->getSetting('general', 'customFieldsUploadsPath'),
204 'customFieldsAllowedExtensions' => $this->getSetting(
205 'general',
206 'customFieldsAllowedExtensions'
207 ),
208 'runInstantPostBookingActions' => $this->getSetting(
209 'general',
210 'runInstantPostBookingActions'
211 ),
212 'sortingPackages' => $this->getSetting('general', 'sortingPackages'),
213 'backLink' => $this->getSetting('general', 'backLink'),
214 'sortingServices' => $this->getSetting('general', 'sortingServices'),
215 'googleRecaptcha' => Licence\Licence::isFeatureEnabledWithLicense(
216 'recaptcha',
217 $this->getSetting('featuresIntegrations', 'recaptcha')
218 ) &&
219 $this->getSetting('general', 'googleRecaptcha')['siteKey'] &&
220 $this->getSetting('general', 'googleRecaptcha')['secret'] ? [
221 'enabled' => true,
222 'invisible' => $this->getSetting('general', 'googleRecaptcha')['invisible'],
223 'siteKey' => $this->getSetting('general', 'googleRecaptcha')['siteKey'],
224 ] : [
225 'enabled' => false,
226 'invisible' => true,
227 'siteKey' => '',
228 ],
229 'usedLanguages' => $this->getSetting('general', 'usedLanguages'),
230 ],
231 'googleMeet' => [
232 'enabled' => $this->getSetting('googleCalendar', 'enableGoogleMeet'),
233 ],
234 'microsoftTeams' => [
235 'enabled' => $this->getSetting('outlookCalendar', 'enableMicrosoftTeams'),
236 ],
237 'googleCalendar' => [
238 'enabled' =>
239 (
240 (
241 $this->getSetting('googleCalendar', 'clientID') &&
242 $this->getSetting('googleCalendar', 'clientSecret')
243 ) ||
244 !empty($this->getSetting('googleCalendar', 'accessToken')) &&
245 $this->getSetting('googleCalendar', 'accessToken') !== 'null'
246 ) &&
247 Licence\Licence::isFeatureEnabledWithLicense(
248 'googleCalendar',
249 $this->getSetting('featuresIntegrations', 'googleCalendar')
250 ),
251 'googleMeetEnabled' => $this->getSetting('googleCalendar', 'enableGoogleMeet'),
252 'accessToken' => !empty($this->getSetting('googleCalendar', 'accessToken')),
253 ],
254 'outlookCalendar' => [
255 'enabled' =>
256 (
257 (
258 $this->getSetting('outlookCalendar', 'clientID') &&
259 $this->getSetting('outlookCalendar', 'clientSecret')
260 ) ||
261 !empty($this->getSetting('outlookCalendar', 'accessToken')) &&
262 $this->getSetting('outlookCalendar', 'accessToken') !== 'null'
263 ) &&
264 Licence\Licence::isFeatureEnabledWithLicense(
265 'outlookCalendar',
266 $this->getSetting('featuresIntegrations', 'outlookCalendar')
267 ),
268 'microsoftTeamsEnabled' => $this->getSetting('outlookCalendar', 'enableMicrosoftTeams'),
269 'accessToken' => !empty($this->getSetting('outlookCalendar', 'accessToken')),
270 ],
271 'appleCalendar' => [
272 'enabled' => Licence\Licence::isFeatureEnabledWithLicense(
273 'appleCalendar',
274 $this->getSetting('featuresIntegrations', 'appleCalendar')
275 ) &&
276 $this->getSetting('appleCalendar', 'clientID') && $this->getSetting('appleCalendar', 'clientSecret'),
277
278 ],
279 'zoom' => [
280 'enabled' => (
281 Licence\Licence::isFeatureEnabledWithLicense(
282 'zoom',
283 $this->getSetting('featuresIntegrations', 'zoom')
284 ) &&
285 $this->getSetting('zoom', 'accountId') &&
286 $this->getSetting('zoom', 'clientId') &&
287 $this->getSetting('zoom', 'clientSecret')
288 )
289 ],
290 'facebookPixel' => Licence\Licence::isFeatureEnabledWithLicense(
291 'facebookPixel',
292 $this->getSetting('featuresIntegrations', 'facebookPixel')
293 )
294 ? $this->getCategorySettings('facebookPixel')
295 : array_merge(
296 $this->getCategorySettings('facebookPixel') ?: [],
297 ['id' => '']
298 ),
299 'googleAnalytics' => Licence\Licence::isFeatureEnabledWithLicense(
300 'googleAnalytics',
301 $this->getSetting('featuresIntegrations', 'googleAnalytics')
302 )
303 ? $this->getCategorySettings('googleAnalytics')
304 : array_merge(
305 $this->getCategorySettings('googleAnalytics') ?: [],
306 ['id' => '']
307 ),
308 'googleTag' => Licence\Licence::isFeatureEnabledWithLicense(
309 'googleTag',
310 $this->getSetting('featuresIntegrations', 'googleTag')
311 )
312 ? $this->getCategorySettings('googleTag')
313 : array_merge(
314 $this->getCategorySettings('googleTag') ?: [],
315 ['id' => '']
316 ),
317 'mailchimp' => [
318 'subscribeFieldVisible' =>
319 Licence\Licence::isFeatureEnabledWithLicense(
320 'mailchimp',
321 $this->getSetting('featuresIntegrations', 'mailchimp')
322 ) &&
323 !empty($this->getSetting('mailchimp', 'accessToken')) &&
324 !empty($this->getSetting('mailchimp', 'list')) &&
325 !empty($this->getSetting('mailchimp', 'server')),
326 'checkedByDefault' => $this->getSetting('mailchimp', 'checkedByDefault'),
327 ],
328 'lessonSpace' => [
329 'enabled' => Licence\Licence::isFeatureEnabledWithLicense(
330 'lessonSpace',
331 $this->getSetting('featuresIntegrations', 'lessonSpace')
332 ) && $this->getSetting('lessonSpace', 'apiKey')
333 ],
334 'socialLogin' => [
335 'googleLoginEnabled' => Licence\Licence::isFeatureEnabledWithLicense(
336 'googleSocialLogin',
337 $this->getSetting('featuresIntegrations', 'googleSocialLogin')
338 ),
339 'facebookLoginEnabled' => Licence\Licence::isFeatureEnabledWithLicense(
340 'facebookSocialLogin',
341 $this->getSetting('featuresIntegrations', 'facebookSocialLogin')
342 ),
343 'facebookAppId' => $this->getSetting('socialLogin', 'facebookAppId'),
344 'facebookCredentialsEnabled' => $this->getSetting('socialLogin', 'facebookAppId') &&
345 $this->getSetting('socialLogin', 'facebookAppSecret'),
346 ],
347 'notifications' => [
348 'senderName' => $this->getSetting('notifications', 'senderName'),
349 'replyTo' => $this->getSetting('notifications', 'replyTo'),
350 'senderEmail' => $this->getSetting('notifications', 'senderEmail'),
351 'invoiceFormat' => $this->getSetting('notifications', 'invoiceFormat'),
352 'sendAllCF' => $this->getSetting('notifications', 'sendAllCF'),
353 'cancelSuccessUrl' => $this->getSetting('notifications', 'cancelSuccessUrl'),
354 'cancelErrorUrl' => $this->getSetting('notifications', 'cancelErrorUrl'),
355 'approveSuccessUrl' => $this->getSetting('notifications', 'approveSuccessUrl'),
356 'approveErrorUrl' => $this->getSetting('notifications', 'approveErrorUrl'),
357 'rejectSuccessUrl' => $this->getSetting('notifications', 'rejectSuccessUrl'),
358 'rejectErrorUrl' => $this->getSetting('notifications', 'rejectErrorUrl'),
359 'smsSignedIn' => $this->getSetting('notifications', 'smsSignedIn'),
360 'bccEmail' => $this->getSetting('notifications', 'bccEmail'),
361 'bccSms' => $this->getSetting('notifications', 'bccSms'),
362 'smsBalanceEmail' => $this->getSetting('notifications', 'smsBalanceEmail'),
363 'whatsAppEnabled' => Licence\Licence::isFeatureEnabledWithLicense(
364 'whatsapp',
365 $this->getSetting('featuresIntegrations', 'whatsapp')
366 ) &&
367 !empty($this->getSetting('notifications', 'whatsAppPhoneID')) &&
368 !empty($this->getSetting('notifications', 'whatsAppAccessToken')) &&
369 !empty($this->getSetting('notifications', 'whatsAppBusinessID')),
370 ],
371 'payments' => [
372 'currency' => $this->getSetting('payments', 'symbol'),
373 'currencyCode' => $this->getSetting('payments', 'currency'),
374 'priceSymbolPosition' => $this->getSetting('payments', 'priceSymbolPosition'),
375 'priceNumberOfDecimals' => $this->getSetting('payments', 'priceNumberOfDecimals'),
376 'priceSeparator' => $this->getSetting('payments', 'priceSeparator'),
377 'hideCurrencySymbolFrontend' => $this->getSetting('payments', 'hideCurrencySymbolFrontend'),
378 'defaultPaymentMethod' => $this->getSetting('payments', 'defaultPaymentMethod'),
379 'onSite' => $this->getSetting('payments', 'onSite'),
380 'couponsCaseInsensitive' => $this->getSetting('payments', 'couponsCaseInsensitive'),
381 'coupons' => Licence\Licence::isFeatureEnabledWithLicense(
382 'coupons',
383 $this->getSetting('featuresIntegrations', 'coupons')
384 ),
385 'taxes' => array_merge(
386 $this->getSetting('payments', 'taxes'),
387 [
388 'enabled' => Licence\Licence::isFeatureEnabledWithLicense(
389 'tax',
390 $this->getSetting('featuresIntegrations', 'tax')
391 )
392 ]
393 ),
394 'cart' => Licence\Licence::isFeatureEnabledWithLicense(
395 'cart',
396 $this->getSetting('featuresIntegrations', 'cart')
397 ),
398 'paymentLinks' => [
399 'enabled' => $this->getSetting('payments', 'paymentLinks')['enabled'],
400 'changeBookingStatus' => $this->getSetting('payments', 'paymentLinks')['changeBookingStatus'],
401 'redirectUrl' => $this->getSetting('payments', 'paymentLinks')['redirectUrl']
402 ],
403 'payPal' => [
404 'enabled' => $this->getSetting('payments', 'payPal')['enabled'],
405 'sandboxMode' => $this->getSetting('payments', 'payPal')['sandboxMode'],
406 'testApiClientId' => $this->getSetting('payments', 'payPal')['testApiClientId'],
407 'liveApiClientId' => $this->getSetting('payments', 'payPal')['liveApiClientId'],
408 ],
409 'stripe' => [
410 'enabled' => $this->getSetting('payments', 'stripe')['enabled'],
411 'testMode' => $this->getSetting('payments', 'stripe')['testMode'],
412 'livePublishableKey' => $this->getSetting('payments', 'stripe')['livePublishableKey'],
413 'testPublishableKey' => $this->getSetting('payments', 'stripe')['testPublishableKey'],
414 'connect' => $this->getSetting('payments', 'stripe')['connect'],
415 'address' => $this->getSetting('payments', 'stripe')['address'],
416 ],
417 'wc' => [
418 'enabled' => $this->getSetting('payments', 'wc')['enabled'],
419 'productId' => $this->getSetting('payments', 'wc')['productId'],
420 'page' => $this->getSetting('payments', 'wc')['page'],
421 'onSiteIfFree' => $this->getSetting('payments', 'wc')['onSiteIfFree']
422 ],
423 'mollie' => [
424 'enabled' => $this->getSetting('payments', 'mollie')['enabled'],
425 'cancelBooking' => $this->getSetting('payments', 'mollie')['cancelBooking'],
426 ],
427 'square' => [
428 'enabled' => $this->getSetting('payments', 'square')['enabled'],
429 'countryCode' => $this->getSetting('payments', 'square')['countryCode'],
430 'clientLiveId' => $this->getSetting('payments', 'square')['clientLiveId'],
431 'clientTestId' => $this->getSetting('payments', 'square')['clientTestId'],
432 'testMode' => $this->getSetting('payments', 'square')['testMode'],
433 'locationId' => $this->getSetting('payments', 'square')['locationId']
434 ],
435 'razorpay' => [
436 'enabled' => $this->getSetting('payments', 'razorpay')['enabled'],
437 ],
438 'barion' => [
439 'enabled' => $this->getSetting('payments', 'barion')['enabled'],
440 ],
441 ],
442 'role' => $userType,
443 'weekSchedule' => $this->getCategorySettings('weekSchedule'),
444 'wordpress' => [
445 'dateFormat' => $this->getSetting('wordpress', 'dateFormat'),
446 'timeFormat' => $this->getSetting('wordpress', 'timeFormat'),
447 'startOfWeek' => (int)$this->getSetting('wordpress', 'startOfWeek'),
448 'timezone' => $this->getSetting('wordpress', 'timeZoneString'),
449 'locale' => AMELIA_LOCALE
450 ],
451 'labels' => [
452 'enabled' => $this->getSetting('labels', 'enabled')
453 ],
454 'activation' => [
455 'showAmeliaSurvey' => $this->getSetting('activation', 'showAmeliaSurvey'),
456 'showAmeliaPromoCustomizePopup' => $this->getSetting('activation', 'showAmeliaPromoCustomizePopup'),
457 'showActivationSettings' => $this->getSetting('activation', 'showActivationSettings'),
458 'stash' => $this->getSetting('activation', 'stash'),
459 'disableUrlParams' => $this->getSetting('activation', 'disableUrlParams'),
460 'isNewInstallation' => $this->getSetting('activation', 'isNewInstallation'),
461 'hideUnavailableFeatures' => $this->getSetting('activation', 'hideUnavailableFeatures'),
462 'licence' => $this->getSetting('activation', 'licence'),
463 'premiumBannerVisibility' => $this->getSetting('activation', 'premiumBannerVisibility'),
464 'dismissibleBannerVisibility' => $this->getSetting('activation', 'dismissibleBannerVisibility'),
465 ],
466 'roles' => [
467 'allowAdminBookAtAnyTime' => $this->getSetting('roles', 'allowAdminBookAtAnyTime'),
468 'allowAdminBookOverApp' => $this->getSetting('roles', 'allowAdminBookOverApp'),
469 'adminServiceDurationAsSlot' => $this->getSetting('roles', 'adminServiceDurationAsSlot'),
470 'allowConfigureSchedule' => $this->getSetting('roles', 'allowConfigureSchedule'),
471 'allowConfigureDaysOff' => $this->getSetting('roles', 'allowConfigureDaysOff'),
472 'allowConfigureSpecialDays' => $this->getSetting('roles', 'allowConfigureSpecialDays'),
473 'allowConfigureServices' => $this->getSetting('roles', 'allowConfigureServices'),
474 'allowWriteAppointments' => $this->getSetting('roles', 'allowWriteAppointments'),
475 'allowWriteCustomers' => $this->getSetting('roles', 'allowWriteCustomers'),
476 'allowReadAllCustomers' => $this->getSetting('roles', 'allowReadAllCustomers'),
477 'automaticallyCreateCustomer' => $this->getSetting('roles', 'automaticallyCreateCustomer'),
478 'inspectCustomerInfo' => $this->getSetting('roles', 'inspectCustomerInfo'),
479 'allowCustomerReschedule' => $this->getSetting('roles', 'allowCustomerReschedule'),
480 'allowCustomerCancelPackages' => $this->getSetting('roles', 'allowCustomerCancelPackages'),
481 'allowCustomerDeleteProfile' => $this->getSetting('roles', 'allowCustomerDeleteProfile'),
482 'allowWriteEvents' => $this->getSetting('roles', 'allowWriteEvents'),
483 'customerCabinet' => [
484 'loginEnabled' => $this->getSetting('roles', 'customerCabinet')['loginEnabled'],
485 'tokenValidTime' => $this->getSetting('roles', 'customerCabinet')['tokenValidTime'],
486 'pageUrl' => $this->getSetting('roles', 'customerCabinet')['pageUrl'],
487 'googleRecaptcha' => Licence\Licence::isFeatureEnabledWithLicense(
488 'recaptcha',
489 $this->getSetting('featuresIntegrations', 'recaptcha')
490 ) &&
491 $this->getSetting('roles', 'customerCabinet')['googleRecaptcha'] &&
492 $this->getSetting('general', 'googleRecaptcha')['siteKey'] &&
493 $this->getSetting('general', 'googleRecaptcha')['secret'],
494 ],
495 'providerCabinet' => [
496 'loginEnabled' => $this->getSetting('roles', 'providerCabinet')['loginEnabled'],
497 'tokenValidTime' => $this->getSetting('roles', 'providerCabinet')['tokenValidTime'],
498 'googleRecaptcha' => Licence\Licence::isFeatureEnabledWithLicense(
499 'recaptcha',
500 $this->getSetting('featuresIntegrations', 'recaptcha')
501 ) &&
502 $this->getSetting('roles', 'providerCabinet')['googleRecaptcha'] &&
503 $this->getSetting('general', 'googleRecaptcha')['siteKey'] &&
504 $this->getSetting('general', 'googleRecaptcha')['secret'],
505 ],
506 'providerBadges' => Licence\Licence::isFeatureEnabledWithLicense(
507 'employeeBadge',
508 $this->getSetting('featuresIntegrations', 'employeeBadge')
509 ) ? $this->getSetting('roles', 'providerBadges') : [],
510 'limitPerCustomerService' => $this->getSetting('roles', 'limitPerCustomerService'),
511 'limitPerCustomerPackage' => $this->getSetting('roles', 'limitPerCustomerPackage'),
512 'limitPerCustomerEvent' => $this->getSetting('roles', 'limitPerCustomerEvent'),
513 'limitPerEmployee' => $this->getSetting('roles', 'limitPerEmployee'),
514 ],
515 'customization' => $this->getCategorySettings('customization'),
516 'customizedData' => $this->getCategorySettings('customizedData'),
517 'appointments' => $this->getCategorySettings('appointments'),
518 'slotDateConstraints' => [
519 'minDate' => DateTimeService::getNowDateTimeObject()
520 ->modify(
521 "+{$this->getSetting('general', 'minimumTimeRequirementPriorToBooking')} seconds"
522 )
523 ->format('Y-m-d H:i:s'),
524 'maxDate' => DateTimeService::getNowDateTimeObject()
525 ->modify(
526 "+{$this->getSetting('general', 'numberOfDaysAvailableForBooking')} day"
527 )
528 ->format('Y-m-d H:i:s')
529 ],
530 'company' => [
531 'email' => $this->getSetting('company', 'email'),
532 'phone' => $this->getSetting('company', 'phone'),
533 ],
534 'pageColumnSettings' => $this->getCategorySettings('pageColumnSettings'),
535 'featuresIntegrations' => Licence\Licence::filterFeaturesByLicense(
536 $this->getCategorySettings('featuresIntegrations')
537 ),
538 ];
539 }
540
541 public function getBackendSettings()
542 {
543 $capabilities = [];
544
545 if (is_admin()) {
546 $entities = [
547 'appointments',
548 'events',
549 'customers',
550 'employees',
551 'services',
552 'packages',
553 'resources',
554 'finance',
555 'coupons',
556 'taxes',
557 'locations',
558 'custom_fields',
559 'notifications',
560 'settings',
561 ];
562
563 foreach ($entities as $entity) {
564 $capabilities = array_merge(
565 $capabilities,
566 [
567 'canRead' . ucfirst($entity) => current_user_can('amelia_read_' . $entity),
568 'canReadOthers' . ucfirst($entity) => current_user_can('amelia_read_others_' . $entity),
569 'canWrite' . ucfirst($entity) => current_user_can('amelia_write_' . $entity),
570 'canWriteOthers' . ucfirst($entity) => current_user_can('amelia_write_others_' . $entity),
571 'canDelete' . ucfirst($entity) => current_user_can('amelia_delete_' . $entity),
572 'canWriteStatus' . ucfirst($entity) => current_user_can('amelia_write_status_' . $entity),
573 ]
574 );
575 }
576 }
577
578 $phoneCountryCode = $this->getSetting('general', 'phoneDefaultCountryCode');
579 $ipLocateApyKey = $this->getSetting('general', 'ipLocateApiKey');
580
581 $wpUser = wp_get_current_user();
582
583 $userType = 'customer';
584
585 if (in_array('administrator', $wpUser->roles, true) || is_super_admin($wpUser->ID)) {
586 $userType = 'admin';
587 } elseif (in_array('wpamelia-manager', $wpUser->roles, true)) {
588 $userType = 'manager';
589 } elseif (in_array('wpamelia-provider', $wpUser->roles, true)) {
590 $userType = 'provider';
591 }
592
593 return [
594 'capabilities' => $capabilities,
595 'activation' => [
596 'licence' => $this->getSetting('activation', 'licence'),
597 'stash' => $this->getSetting('activation', 'stash'),
598 'hideUnavailableFeatures' => $this->getSetting('activation', 'hideUnavailableFeatures'),
599 'hideTipsAndSuggestions' => $this->getSetting('activation', 'hideTipsAndSuggestions'),
600 ],
601 'appleCalendar' => [
602 'active' => Licence\Licence::isFeatureEnabledWithLicense(
603 'appleCalendar',
604 $this->getSetting('featuresIntegrations', 'appleCalendar')
605 ) &&
606 $this->getSetting('appleCalendar', 'clientID') &&
607 $this->getSetting('appleCalendar', 'clientSecret'),
608 ],
609 'appointments' => [
610 'cartPlaceholders' => $this->getSetting('appointments', 'cartPlaceholders'),
611 'cartPlaceholdersCustomer' => $this->getSetting('appointments', 'cartPlaceholdersCustomer'),
612 'cartPlaceholdersCustomerSms' => $this->getSetting(
613 'appointments',
614 'cartPlaceholdersCustomerSms'
615 ),
616 'cartPlaceholdersSms' => $this->getSetting('appointments', 'cartPlaceholdersSms'),
617 'groupAppointmentPlaceholder' => $this->getSetting(
618 'appointments',
619 'groupAppointmentPlaceholder'
620 ),
621 'groupAppointmentPlaceholderCustomer' => $this->getSetting(
622 'appointments',
623 'groupAppointmentPlaceholderCustomer'
624 ),
625 'groupAppointmentPlaceholderSms' => $this->getSetting(
626 'appointments',
627 'groupAppointmentPlaceholderSms'
628 ),
629 'groupEventPlaceholder' => $this->getSetting('appointments', 'groupEventPlaceholder'),
630 'groupEventPlaceholderCustomer' => $this->getSetting(
631 'appointments',
632 'groupEventPlaceholderCustomer'
633 ),
634 'groupEventPlaceholderSms' => $this->getSetting('appointments', 'groupEventPlaceholderSms'),
635 'packagePlaceholders' => $this->getSetting('appointments', 'packagePlaceholders'),
636 'packagePlaceholdersCustomer' => $this->getSetting(
637 'appointments',
638 'packagePlaceholdersCustomer'
639 ),
640 'packagePlaceholdersCustomerSms' => $this->getSetting(
641 'appointments',
642 'packagePlaceholdersCustomerSms'
643 ),
644 'packagePlaceholdersSms' => $this->getSetting('appointments', 'packagePlaceholdersSms'),
645 'recurringPlaceholders' => $this->getSetting('appointments', 'recurringPlaceholders'),
646 'recurringPlaceholdersCustomer' => $this->getSetting(
647 'appointments',
648 'recurringPlaceholdersCustomer'
649 ),
650 'recurringPlaceholdersCustomerSms' => $this->getSetting(
651 'appointments',
652 'recurringPlaceholdersCustomerSms'
653 ),
654 'recurringPlaceholdersSms' => $this->getSetting('appointments', 'recurringPlaceholdersSms'),
655 'waitingListAppointments' => $this->getSetting('appointments', 'waitingListAppointments'),
656 ],
657 'daysOff' => $this->getCategorySettings('daysOff'),
658 'events' => [
659 'waitingListEvents' => [
660 'addingMethod' => $this->getSetting('appointments', 'waitingListEvents')['addingMethod'],
661 ],
662 ],
663 'featuresIntegrations' => Licence\Licence::filterFeaturesByLicense(
664 $this->getCategorySettings('featuresIntegrations')
665 ),
666 'general' => [
667 'customFieldsBackendValidation' => $this->getSetting('general', 'customFieldsBackendValidation'),
668 'customersFilterLimit' => $this->getSetting('general', 'customersFilterLimit'),
669 'defaultAppointmentStatus' => $this->getSetting('general', 'defaultAppointmentStatus'),
670 'gMapApiKey' => $this->getSetting('general', 'gMapApiKey'),
671 'minimumTimeRequirementPriorToBooking' => $this->getSetting(
672 'general',
673 'minimumTimeRequirementPriorToBooking'
674 ),
675 'minimumTimeRequirementPriorToCanceling' => $this->getSetting(
676 'general',
677 'minimumTimeRequirementPriorToCanceling'
678 ),
679 'minimumTimeRequirementPriorToRescheduling' => $this->getSetting(
680 'general',
681 'minimumTimeRequirementPriorToRescheduling'
682 ),
683 'numberOfDaysAvailableForBooking' => $this->getSetting(
684 'general',
685 'numberOfDaysAvailableForBooking'
686 ),
687 'phoneDefaultCountryCode' => $phoneCountryCode === 'auto' ? $this->locationService->getCurrentLocationCountryIso(
688 $ipLocateApyKey
689 ) : $phoneCountryCode,
690 'redirectUrlAfterAppointment' => $this->getSetting(
691 'general',
692 'redirectUrlAfterAppointment'
693 ),
694 'sortingPackages' => $this->getSetting('general', 'sortingPackages'),
695 'sortingServices' => $this->getSetting('general', 'sortingServices'),
696 'timeSlotLength' => $this->getSetting('general', 'timeSlotLength'),
697 'usedLanguages' => $this->getSetting('general', 'usedLanguages'),
698 ],
699 'googleCalendar' => [
700 'active' => Licence\Licence::isFeatureEnabledWithLicense(
701 'googleCalendar',
702 $this->getSetting('featuresIntegrations', 'googleCalendar')
703 ) &&
704 (($this->getSetting('googleCalendar', 'clientID') &&
705 $this->getSetting('googleCalendar', 'clientSecret')) ||
706 $this->getSetting('googleCalendar', 'accessToken')),
707 'googleMeet' => $this->getSetting('googleCalendar', 'enableGoogleMeet'),
708 'hasAccessToken' => !empty($this->getSetting('googleCalendar', 'accessToken')) &&
709 $this->getSetting('googleCalendar', 'accessToken') !== 'null',
710
711 ],
712 'lessonSpace' => [
713 'active' =>
714 Licence\Licence::isFeatureEnabledWithLicense(
715 'lessonSpace',
716 $this->getSetting('featuresIntegrations', 'lessonSpace')
717 ) && $this->getSetting('lessonSpace', 'apiKey')
718 ],
719 'socialLogin' => [
720 'googleLoginEnabled' => Licence\Licence::isFeatureEnabledWithLicense(
721 'googleSocialLogin',
722 $this->getSetting('featuresIntegrations', 'googleSocialLogin')
723 ),
724 'facebookLoginEnabled' => Licence\Licence::isFeatureEnabledWithLicense(
725 'facebookSocialLogin',
726 $this->getSetting('featuresIntegrations', 'facebookSocialLogin')
727 ),
728 'facebookAppId' => $this->getSetting('socialLogin', 'facebookAppId'),
729 'facebookCredentialsEnabled' => $this->getSetting('socialLogin', 'facebookAppId') &&
730 $this->getSetting('socialLogin', 'facebookAppSecret'),
731 ],
732 'mailchimp' => [
733 'subscribeFieldVisible' =>
734 Licence\Licence::isFeatureEnabledWithLicense(
735 'mailchimp',
736 $this->getSetting('featuresIntegrations', 'mailchimp')
737 ) &&
738 !empty($this->getSetting('mailchimp', 'accessToken')) &&
739 !empty($this->getSetting('mailchimp', 'list')) &&
740 !empty($this->getSetting('mailchimp', 'server')),
741 'checkedByDefault' => $this->getSetting('mailchimp', 'checkedByDefault'),
742 ],
743 'notifications' => [
744 'sendAllCF' => $this->getSetting('notifications', 'sendAllCF'),
745 'senderEmail' => $this->getSetting('notifications', 'senderEmail'),
746 'sms' => [
747 'signedIn' => $this->getSetting('notifications', 'smsSignedIn'),
748 ],
749 'whatsApp' => [
750 'active' => Licence\Licence::isFeatureEnabledWithLicense(
751 'whatsapp',
752 $this->getSetting('featuresIntegrations', 'whatsapp')
753 )
754 && $this->getSetting('notifications', 'whatsAppPhoneID')
755 && $this->getSetting('notifications', 'whatsAppAccessToken')
756 && $this->getSetting('notifications', 'whatsAppBusinessID'),
757 'phoneId' => $this->getSetting('notifications', 'whatsAppPhoneID'),
758 ],
759 ],
760 'outlookCalendar' => [
761 'active' => Licence\Licence::isFeatureEnabledWithLicense(
762 'outlookCalendar',
763 $this->getSetting('featuresIntegrations', 'outlookCalendar')
764 ) &&
765 (($this->getSetting('outlookCalendar', 'clientID') &&
766 $this->getSetting('outlookCalendar', 'clientSecret')) ||
767 $this->getSetting('outlookCalendar', 'accessToken')),
768 'microsoftTeams' => $this->getSetting('outlookCalendar', 'enableMicrosoftTeams'),
769 'hasAccessToken' => !empty($this->getSetting('outlookCalendar', 'accessToken')) &&
770 $this->getSetting('outlookCalendar', 'accessToken') !== 'null',
771
772 ],
773 'pageColumnSettings' => $this->getCategorySettings('pageColumnSettings'),
774 'payments' => [
775 'barion' => [
776 'active' =>
777 Licence\Licence::isFeatureEnabledWithLicense(
778 'barion',
779 $this->getSetting('featuresIntegrations', 'barion')
780 ) &&
781 $this->getSetting('payments', 'barion')['enabled'] &&
782 (($this->getSetting('payments', 'barion')['sandboxMode'] && $this->getSetting(
783 'payments',
784 'barion'
785 )['sandboxPOSKey'] && $this->getSetting('payments', 'barion')['payeeEmail']) ||
786 (! $this->getSetting('payments', 'barion')['sandboxMode'] && $this->getSetting(
787 'payments',
788 'barion'
789 )['livePOSKey'] && $this->getSetting('payments', 'barion')['payeeEmail']))
790 ],
791 'currency' => $this->getSetting('payments', 'symbol'),
792 'defaultPaymentMethod' => $this->getSetting('payments', 'defaultPaymentMethod'),
793 'mollie' => [
794 'active' =>
795 Licence\Licence::isFeatureEnabledWithLicense(
796 'mollie',
797 $this->getSetting('featuresIntegrations', 'mollie')
798 ) &&
799 $this->getSetting('payments', 'mollie')['enabled'] &&
800 (($this->getSetting('payments', 'mollie')['testMode'] && $this->getSetting(
801 'payments',
802 'mollie'
803 )['testApiKey']) ||
804 (! $this->getSetting('payments', 'mollie')['testMode'] && $this->getSetting(
805 'payments',
806 'mollie'
807 )['liveApiKey']))
808 ],
809 'onSite' => $this->getSetting('payments', 'onSite'),
810 'taxes' => array_merge(
811 $this->getSetting('payments', 'taxes'),
812 [
813 'enabled' => Licence\Licence::isFeatureEnabledWithLicense(
814 'tax',
815 $this->getSetting('featuresIntegrations', 'tax')
816 )
817 ]
818 ),
819 'paymentLinks' => [
820 'enabled' => $this->getSetting('payments', 'paymentLinks')['enabled'],
821 'changeBookingStatus' => $this->getSetting('payments', 'paymentLinks')['changeBookingStatus'],
822 'redirectUrl' => $this->getSetting('payments', 'paymentLinks')['redirectUrl']
823 ],
824 'payPal' => [
825 'active' =>
826 Licence\Licence::isFeatureEnabledWithLicense(
827 'payPal',
828 $this->getSetting('featuresIntegrations', 'payPal')
829 ) &&
830 $this->getSetting('payments', 'payPal')['enabled'] &&
831 (($this->getSetting('payments', 'payPal')['sandboxMode'] && $this->getSetting(
832 'payments',
833 'payPal'
834 )['testApiClientId'] && $this->getSetting('payments', 'payPal')['testApiSecret']) ||
835 (! $this->getSetting('payments', 'payPal')['sandboxMode'] && $this->getSetting(
836 'payments',
837 'payPal'
838 )['liveApiClientId'] && $this->getSetting('payments', 'payPal')['liveApiSecret']))
839 ],
840 'priceNumberOfDecimals' => $this->getSetting('payments', 'priceNumberOfDecimals'),
841 'priceSeparator' => $this->getSetting('payments', 'priceSeparator'),
842 'priceSymbolPosition' => $this->getSetting('payments', 'priceSymbolPosition'),
843 'razorpay' => [
844 'active' =>
845 Licence\Licence::isFeatureEnabledWithLicense(
846 'razorpay',
847 $this->getSetting('featuresIntegrations', 'razorpay')
848 ) &&
849 $this->getSetting('payments', 'razorpay')['enabled'] &&
850 (($this->getSetting('payments', 'razorpay')['testMode'] && $this->getSetting(
851 'payments',
852 'razorpay'
853 )['testKeyId'] && $this->getSetting('payments', 'razorpay')['testKeySecret']) ||
854 (! $this->getSetting('payments', 'razorpay')['testMode'] && $this->getSetting(
855 'payments',
856 'razorpay'
857 )['liveKeyId'] && $this->getSetting('payments', 'razorpay')['liveKeySecret']))
858 ],
859 'stripe' => [
860 'active' =>
861 Licence\Licence::isFeatureEnabledWithLicense(
862 'stripe',
863 $this->getSetting('featuresIntegrations', 'stripe')
864 ) &&
865 $this->getSetting('payments', 'stripe')['enabled'] &&
866 (($this->getSetting('payments', 'stripe')['testMode'] && $this->getSetting(
867 'payments',
868 'stripe'
869 )['testPublishableKey'] && $this->getSetting('payments', 'stripe')['testSecretKey']) ||
870 (! $this->getSetting('payments', 'stripe')['testMode'] && $this->getSetting(
871 'payments',
872 'stripe'
873 )['livePublishableKey'] && $this->getSetting('payments', 'stripe')['liveSecretKey'])),
874 'connect' => $this->getSetting('payments', 'stripe')['connect'],
875 ],
876 'square' => [
877 'active' =>
878 Licence\Licence::isFeatureEnabledWithLicense(
879 'square',
880 $this->getSetting('featuresIntegrations', 'square')
881 ) &&
882 $this->getSetting('payments', 'square')['enabled'] &&
883 $this->getSetting('payments', 'square')['accessToken'] &&
884 $this->getSetting('payments', 'square')['locationId']
885 ],
886 'wc' => [
887 'active' => Licence\Licence::isFeatureEnabledWithLicense(
888 'wc',
889 $this->getSetting('featuresIntegrations', 'wc')
890 ) &&
891 $this->getSetting('payments', 'wc')['enabled'],
892 'productId' => $this->getSetting('payments', 'wc')['productId'],
893 ]
894 ],
895
896 'role' => $userType,
897 'roles' => [
898 'providerBadges' => Licence\Licence::isFeatureEnabledWithLicense(
899 'employeeBadge',
900 $this->getSetting('featuresIntegrations', 'employeeBadge')
901 ) ? $this->getSetting('roles', 'providerBadges') : [],
902 'allowCustomerReschedule' => $this->getSetting('roles', 'allowCustomerReschedule'),
903 'allowConfigureSchedule' => $this->getSetting('roles', 'allowConfigureSchedule'),
904 'allowConfigureDaysOff' => $this->getSetting('roles', 'allowConfigureDaysOff'),
905 'allowConfigureSpecialDays' => $this->getSetting('roles', 'allowConfigureSpecialDays'),
906 'allowConfigureServices' => $this->getSetting('roles', 'allowConfigureServices'),
907 'allowWriteAppointments' => $this->getSetting('roles', 'allowWriteAppointments'),
908 'allowWriteEvents' => $this->getSetting('roles', 'allowWriteEvents'),
909 ],
910 'weekSchedule' => $this->getCategorySettings('weekSchedule'),
911 'wordpress' => [
912 'dateFormat' => $this->getSetting('wordpress', 'dateFormat'),
913 'locale' => AMELIA_LOCALE,
914 'startOfWeek' => (int)$this->getSetting('wordpress', 'startOfWeek'),
915 'timeFormat' => $this->getSetting('wordpress', 'timeFormat'),
916 'timezone' => $this->getSetting('wordpress', 'timeZoneString'),
917 'gmtOffset' => $this->getSetting('wordpress', 'gmtOffset'),
918 ],
919 'zoom' => [
920 'active' => (
921 Licence\Licence::isFeatureEnabledWithLicense(
922 'zoom',
923 $this->getSetting('featuresIntegrations', 'zoom')
924 ) &&
925 $this->getSetting('zoom', 'accountId') &&
926 $this->getSetting('zoom', 'clientId') &&
927 $this->getSetting('zoom', 'clientSecret')
928 )
929 ],
930 ];
931 }
932
933 /**
934 * @param $settingCategoryKey
935 * @param $settingKey
936 * @param $settingValue
937 *
938 * @return mixed|void
939 */
940 public function setSetting($settingCategoryKey, $settingKey, $settingValue)
941 {
942 $this->settingsCache[$settingCategoryKey][$settingKey] = $settingValue;
943 $settingsCopy = $this->settingsCache;
944
945 unset($settingsCopy['wordpress']);
946 update_option('amelia_settings', json_encode($settingsCopy));
947 }
948
949 /**
950 * @param $settingCategoryKey
951 * @param $settingValues
952 *
953 * @return mixed|void
954 */
955 public function setCategorySettings($settingCategoryKey, $settingValues)
956 {
957 $this->settingsCache[$settingCategoryKey] = $settingValues;
958 $settingsCopy = $this->settingsCache;
959
960 unset($settingsCopy['wordpress']);
961 update_option('amelia_settings', json_encode($settingsCopy));
962 }
963
964 /**
965 * @param array $settings
966 *
967 * @return mixed|void
968 */
969 public function setAllSettings($settings)
970 {
971 foreach ($settings as $settingCategoryKey => $settingValues) {
972 $this->settingsCache[$settingCategoryKey] = $settingValues;
973 }
974 $settingsCopy = $this->settingsCache;
975
976 Licence\DataModifier::restoreSettings($settingsCopy, self::getSavedSettings());
977
978 if (get_option('amelia_show_wpdt_promo') === false) {
979 update_option('amelia_show_wpdt_promo', 'yes');
980 }
981
982 unset($settingsCopy['wordpress']);
983 update_option('amelia_settings', json_encode($settingsCopy));
984 }
985 }
986