PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.1.3
Booking for Appointments and Events Calendar – Amelia v2.1.3
2.4.9 2.4.8 2.4.7 2.4.6 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 5 months ago
SettingsStorage.php
988 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' => $this->getSetting('general', 'gMapApiKey'),
178 'googleClientId' => $this->getSetting('googleCalendar', 'clientID'),
179 'googleAccessToken' => $this->getSetting('googleCalendar', 'accessToken'),
180 'googleAccountData' => $this->getSetting('googleCalendar', 'googleAccountData'),
181 'outlookAccessToken' => $this->getSetting('outlookCalendar', 'accessToken'),
182 'outlookAccountData' => $this->getSetting('outlookCalendar', 'outlookAccountData'),
183 'addToCalendar' => $this->getSetting('general', 'addToCalendar'),
184 'requiredPhoneNumberField' => $this->getSetting('general', 'requiredPhoneNumberField'),
185 'requiredEmailField' => $this->getSetting('general', 'requiredEmailField'),
186 'numberOfDaysAvailableForBooking' => $this->getSetting(
187 'general',
188 'numberOfDaysAvailableForBooking'
189 ),
190 'minimumTimeRequirementPriorToBooking' =>
191 $this->getSetting('general', 'minimumTimeRequirementPriorToBooking'),
192 'minimumTimeRequirementPriorToCanceling' =>
193 $this->getSetting('general', 'minimumTimeRequirementPriorToCanceling'),
194 'minimumTimeRequirementPriorToRescheduling' =>
195 $this->getSetting('general', 'minimumTimeRequirementPriorToRescheduling'),
196 'showClientTimeZone' => $this->getSetting(
197 'general',
198 'showClientTimeZone'
199 ),
200 'redirectUrlAfterAppointment' => $this->getSetting(
201 'general',
202 'redirectUrlAfterAppointment'
203 ),
204 'customFieldsUploadsPath' => $this->getSetting('general', 'customFieldsUploadsPath'),
205 'customFieldsAllowedExtensions' => $this->getSetting(
206 'general',
207 'customFieldsAllowedExtensions'
208 ),
209 'runInstantPostBookingActions' => $this->getSetting(
210 'general',
211 'runInstantPostBookingActions'
212 ),
213 'sortingPackages' => $this->getSetting('general', 'sortingPackages'),
214 'backLink' => $this->getSetting('general', 'backLink'),
215 'sortingServices' => $this->getSetting('general', 'sortingServices'),
216 'googleRecaptcha' => Licence\Licence::isFeatureEnabledWithLicense(
217 'recaptcha',
218 $this->getSetting('featuresIntegrations', 'recaptcha')
219 ) &&
220 $this->getSetting('general', 'googleRecaptcha')['siteKey'] &&
221 $this->getSetting('general', 'googleRecaptcha')['secret'] ? [
222 'enabled' => true,
223 'invisible' => $this->getSetting('general', 'googleRecaptcha')['invisible'],
224 'siteKey' => $this->getSetting('general', 'googleRecaptcha')['siteKey'],
225 ] : [
226 'enabled' => false,
227 'invisible' => true,
228 'siteKey' => '',
229 ],
230 'usedLanguages' => $this->getSetting('general', 'usedLanguages'),
231 ],
232 'googleMeet' => [
233 'enabled' => $this->getSetting('googleCalendar', 'enableGoogleMeet'),
234 ],
235 'microsoftTeams' => [
236 'enabled' => $this->getSetting('outlookCalendar', 'enableMicrosoftTeams'),
237 ],
238 'googleCalendar' => [
239 'enabled' =>
240 (
241 (
242 $this->getSetting('googleCalendar', 'clientID') &&
243 $this->getSetting('googleCalendar', 'clientSecret')
244 ) ||
245 !empty($this->getSetting('googleCalendar', 'accessToken')) &&
246 $this->getSetting('googleCalendar', 'accessToken') !== 'null'
247 ) &&
248 Licence\Licence::isFeatureEnabledWithLicense(
249 'googleCalendar',
250 $this->getSetting('featuresIntegrations', 'googleCalendar')
251 ),
252 'googleMeetEnabled' => $this->getSetting('googleCalendar', 'enableGoogleMeet'),
253 'accessToken' => $this->getSetting('googleCalendar', 'accessToken'),
254 ],
255 'outlookCalendar' => [
256 'enabled' =>
257 (
258 (
259 $this->getSetting('outlookCalendar', 'clientID') &&
260 $this->getSetting('outlookCalendar', 'clientSecret')
261 ) ||
262 !empty($this->getSetting('outlookCalendar', 'accessToken')) &&
263 $this->getSetting('outlookCalendar', 'accessToken') !== 'null'
264 ) &&
265 Licence\Licence::isFeatureEnabledWithLicense(
266 'outlookCalendar',
267 $this->getSetting('featuresIntegrations', 'outlookCalendar')
268 ),
269 'microsoftTeamsEnabled' => $this->getSetting('outlookCalendar', 'enableMicrosoftTeams'),
270 'accessToken' => $this->getSetting('outlookCalendar', 'accessToken'),
271 ],
272 'appleCalendar' =>
273 $this->getSetting('appleCalendar', 'clientID') && $this->getSetting('appleCalendar', 'clientSecret'),
274 'zoom' => [
275 'enabled' => (
276 Licence\Licence::isFeatureEnabledWithLicense(
277 'zoom',
278 $this->getSetting('featuresIntegrations', 'zoom')
279 ) &&
280 $this->getSetting('zoom', 'accountId') &&
281 $this->getSetting('zoom', 'clientId') &&
282 $this->getSetting('zoom', 'clientSecret')
283 )
284 ],
285 'facebookPixel' => Licence\Licence::isFeatureEnabledWithLicense(
286 'facebookPixel',
287 $this->getSetting('featuresIntegrations', 'facebookPixel')
288 )
289 ? $this->getCategorySettings('facebookPixel')
290 : array_merge(
291 $this->getCategorySettings('facebookPixel') ?: [],
292 ['id' => '']
293 ),
294 'googleAnalytics' => Licence\Licence::isFeatureEnabledWithLicense(
295 'googleAnalytics',
296 $this->getSetting('featuresIntegrations', 'googleAnalytics')
297 )
298 ? $this->getCategorySettings('googleAnalytics')
299 : array_merge(
300 $this->getCategorySettings('googleAnalytics') ?: [],
301 ['id' => '']
302 ),
303 'googleTag' => Licence\Licence::isFeatureEnabledWithLicense(
304 'googleTag',
305 $this->getSetting('featuresIntegrations', 'googleTag')
306 )
307 ? $this->getCategorySettings('googleTag')
308 : array_merge(
309 $this->getCategorySettings('googleTag') ?: [],
310 ['id' => '']
311 ),
312 'mailchimp' => [
313 'subscribeFieldVisible' =>
314 Licence\Licence::isFeatureEnabledWithLicense(
315 'mailchimp',
316 $this->getSetting('featuresIntegrations', 'mailchimp')
317 ) &&
318 !empty($this->getSetting('mailchimp', 'accessToken')) &&
319 !empty($this->getSetting('mailchimp', 'list')) &&
320 !empty($this->getSetting('mailchimp', 'server')),
321 'checkedByDefault' => $this->getSetting('mailchimp', 'checkedByDefault'),
322 ],
323 'lessonSpace' => [
324 'enabled' => Licence\Licence::isFeatureEnabledWithLicense(
325 'lessonSpace',
326 $this->getSetting('featuresIntegrations', 'lessonSpace')
327 ) && $this->getSetting('lessonSpace', 'apiKey')
328 ],
329 'socialLogin' => [
330 'googleLoginEnabled' => Licence\Licence::isFeatureEnabledWithLicense(
331 'googleSocialLogin',
332 $this->getSetting('featuresIntegrations', 'googleSocialLogin')
333 ),
334 'facebookLoginEnabled' => Licence\Licence::isFeatureEnabledWithLicense(
335 'facebookSocialLogin',
336 $this->getSetting('featuresIntegrations', 'facebookSocialLogin')
337 ),
338 'facebookAppId' => $this->getSetting('socialLogin', 'facebookAppId'),
339 'facebookCredentialsEnabled' => $this->getSetting('socialLogin', 'facebookAppId') &&
340 $this->getSetting('socialLogin', 'facebookAppSecret'),
341 ],
342 'notifications' => [
343 'senderName' => $this->getSetting('notifications', 'senderName'),
344 'replyTo' => $this->getSetting('notifications', 'replyTo'),
345 'senderEmail' => $this->getSetting('notifications', 'senderEmail'),
346 'invoiceFormat' => $this->getSetting('notifications', 'invoiceFormat'),
347 'sendAllCF' => $this->getSetting('notifications', 'sendAllCF'),
348 'cancelSuccessUrl' => $this->getSetting('notifications', 'cancelSuccessUrl'),
349 'cancelErrorUrl' => $this->getSetting('notifications', 'cancelErrorUrl'),
350 'approveSuccessUrl' => $this->getSetting('notifications', 'approveSuccessUrl'),
351 'approveErrorUrl' => $this->getSetting('notifications', 'approveErrorUrl'),
352 'rejectSuccessUrl' => $this->getSetting('notifications', 'rejectSuccessUrl'),
353 'rejectErrorUrl' => $this->getSetting('notifications', 'rejectErrorUrl'),
354 'smsSignedIn' => $this->getSetting('notifications', 'smsSignedIn'),
355 'bccEmail' => $this->getSetting('notifications', 'bccEmail'),
356 'bccSms' => $this->getSetting('notifications', 'bccSms'),
357 'smsBalanceEmail' => $this->getSetting('notifications', 'smsBalanceEmail'),
358 'whatsAppPhoneID' => $this->getSetting('notifications', 'whatsAppPhoneID'),
359 'whatsAppAccessToken' => $this->getSetting('notifications', 'whatsAppAccessToken'),
360 'whatsAppBusinessID' => $this->getSetting('notifications', 'whatsAppBusinessID'),
361 'whatsAppLanguage' => $this->getSetting('notifications', 'whatsAppLanguage'),
362 'whatsAppEnabled' => Licence\Licence::isFeatureEnabledWithLicense(
363 'whatsapp',
364 $this->getSetting('featuresIntegrations', 'whatsapp')
365 ),
366 ],
367 'payments' => [
368 'currency' => $this->getSetting('payments', 'symbol'),
369 'currencyCode' => $this->getSetting('payments', 'currency'),
370 'priceSymbolPosition' => $this->getSetting('payments', 'priceSymbolPosition'),
371 'priceNumberOfDecimals' => $this->getSetting('payments', 'priceNumberOfDecimals'),
372 'priceSeparator' => $this->getSetting('payments', 'priceSeparator'),
373 'hideCurrencySymbolFrontend' => $this->getSetting('payments', 'hideCurrencySymbolFrontend'),
374 'defaultPaymentMethod' => $this->getSetting('payments', 'defaultPaymentMethod'),
375 'onSite' => $this->getSetting('payments', 'onSite'),
376 'couponsCaseInsensitive' => $this->getSetting('payments', 'couponsCaseInsensitive'),
377 'coupons' => Licence\Licence::isFeatureEnabledWithLicense(
378 'coupons',
379 $this->getSetting('featuresIntegrations', 'coupons')
380 ),
381 'taxes' => array_merge(
382 $this->getSetting('payments', 'taxes'),
383 [
384 'enabled' => Licence\Licence::isFeatureEnabledWithLicense(
385 'tax',
386 $this->getSetting('featuresIntegrations', 'tax')
387 )
388 ]
389 ),
390 'cart' => Licence\Licence::isFeatureEnabledWithLicense(
391 'cart',
392 $this->getSetting('featuresIntegrations', 'cart')
393 ),
394 'paymentLinks' => [
395 'enabled' => $this->getSetting('payments', 'paymentLinks')['enabled'],
396 'changeBookingStatus' => $this->getSetting('payments', 'paymentLinks')['changeBookingStatus'],
397 'redirectUrl' => $this->getSetting('payments', 'paymentLinks')['redirectUrl']
398 ],
399 'payPal' => [
400 'enabled' => $this->getSetting('payments', 'payPal')['enabled'],
401 'sandboxMode' => $this->getSetting('payments', 'payPal')['sandboxMode'],
402 'testApiClientId' => $this->getSetting('payments', 'payPal')['testApiClientId'],
403 'liveApiClientId' => $this->getSetting('payments', 'payPal')['liveApiClientId'],
404 ],
405 'stripe' => [
406 'enabled' => $this->getSetting('payments', 'stripe')['enabled'],
407 'testMode' => $this->getSetting('payments', 'stripe')['testMode'],
408 'livePublishableKey' => $this->getSetting('payments', 'stripe')['livePublishableKey'],
409 'testPublishableKey' => $this->getSetting('payments', 'stripe')['testPublishableKey'],
410 'connect' => $this->getSetting('payments', 'stripe')['connect'],
411 'address' => $this->getSetting('payments', 'stripe')['address'],
412 ],
413 'wc' => [
414 'enabled' => $this->getSetting('payments', 'wc')['enabled'],
415 'productId' => $this->getSetting('payments', 'wc')['productId'],
416 'page' => $this->getSetting('payments', 'wc')['page'],
417 'onSiteIfFree' => $this->getSetting('payments', 'wc')['onSiteIfFree']
418 ],
419 'mollie' => [
420 'enabled' => $this->getSetting('payments', 'mollie')['enabled'],
421 'cancelBooking' => $this->getSetting('payments', 'mollie')['cancelBooking'],
422 ],
423 'square' => [
424 'enabled' => $this->getSetting('payments', 'square')['enabled'],
425 'countryCode' => $this->getSetting('payments', 'square')['countryCode'],
426 'clientLiveId' => $this->getSetting('payments', 'square')['clientLiveId'],
427 'clientTestId' => $this->getSetting('payments', 'square')['clientTestId'],
428 'testMode' => $this->getSetting('payments', 'square')['testMode'],
429 'accessTokenSet' =>
430 !empty($this->getSetting('payments', 'square')['accessToken']) &&
431 !empty($this->getSetting('payments', 'square')['accessToken']['access_token']),
432 'locationId' => $this->getSetting('payments', 'square')['locationId']
433 ],
434 'razorpay' => [
435 'enabled' => $this->getSetting('payments', 'razorpay')['enabled'],
436 ],
437 'barion' => [
438 'enabled' => $this->getSetting('payments', 'barion')['enabled'],
439 'sandboxMode' => $this->getSetting('payments', 'barion')['sandboxMode'],
440 'livePOSKey' => $this->getSetting('payments', 'barion')['livePOSKey'],
441 'sandboxPOSKey' => $this->getSetting('payments', 'barion')['sandboxPOSKey'],
442 'payeeEmail' => $this->getSetting('payments', 'barion')['payeeEmail'],
443 ],
444 ],
445 'role' => $userType,
446 'weekSchedule' => $this->getCategorySettings('weekSchedule'),
447 'wordpress' => [
448 'dateFormat' => $this->getSetting('wordpress', 'dateFormat'),
449 'timeFormat' => $this->getSetting('wordpress', 'timeFormat'),
450 'startOfWeek' => (int)$this->getSetting('wordpress', 'startOfWeek'),
451 'timezone' => $this->getSetting('wordpress', 'timeZoneString'),
452 'locale' => AMELIA_LOCALE
453 ],
454 'labels' => [
455 'enabled' => $this->getSetting('labels', 'enabled')
456 ],
457 'activation' => [
458 'showAmeliaSurvey' => $this->getSetting('activation', 'showAmeliaSurvey'),
459 'showAmeliaPromoCustomizePopup' => $this->getSetting('activation', 'showAmeliaPromoCustomizePopup'),
460 'showActivationSettings' => $this->getSetting('activation', 'showActivationSettings'),
461 'stash' => $this->getSetting('activation', 'stash'),
462 'disableUrlParams' => $this->getSetting('activation', 'disableUrlParams'),
463 'isNewInstallation' => $this->getSetting('activation', 'isNewInstallation'),
464 'hideUnavailableFeatures' => $this->getSetting('activation', 'hideUnavailableFeatures'),
465 'licence' => $this->getSetting('activation', 'licence'),
466 'premiumBannerVisibility' => $this->getSetting('activation', 'premiumBannerVisibility'),
467 'dismissibleBannerVisibility' => $this->getSetting('activation', 'dismissibleBannerVisibility'),
468 ],
469 'roles' => [
470 'allowAdminBookAtAnyTime' => $this->getSetting('roles', 'allowAdminBookAtAnyTime'),
471 'allowAdminBookOverApp' => $this->getSetting('roles', 'allowAdminBookOverApp'),
472 'adminServiceDurationAsSlot' => $this->getSetting('roles', 'adminServiceDurationAsSlot'),
473 'allowConfigureSchedule' => $this->getSetting('roles', 'allowConfigureSchedule'),
474 'allowConfigureDaysOff' => $this->getSetting('roles', 'allowConfigureDaysOff'),
475 'allowConfigureSpecialDays' => $this->getSetting('roles', 'allowConfigureSpecialDays'),
476 'allowConfigureServices' => $this->getSetting('roles', 'allowConfigureServices'),
477 'allowWriteAppointments' => $this->getSetting('roles', 'allowWriteAppointments'),
478 'allowWriteCustomers' => $this->getSetting('roles', 'allowWriteCustomers'),
479 'automaticallyCreateCustomer' => $this->getSetting('roles', 'automaticallyCreateCustomer'),
480 'inspectCustomerInfo' => $this->getSetting('roles', 'inspectCustomerInfo'),
481 'allowCustomerReschedule' => $this->getSetting('roles', 'allowCustomerReschedule'),
482 'allowCustomerCancelPackages' => $this->getSetting('roles', 'allowCustomerCancelPackages'),
483 'allowCustomerDeleteProfile' => $this->getSetting('roles', 'allowCustomerDeleteProfile'),
484 'allowWriteEvents' => $this->getSetting('roles', 'allowWriteEvents'),
485 'customerCabinet' => [
486 'loginEnabled' => $this->getSetting('roles', 'customerCabinet')['loginEnabled'],
487 'tokenValidTime' => $this->getSetting('roles', 'customerCabinet')['tokenValidTime'],
488 'pageUrl' => $this->getSetting('roles', 'customerCabinet')['pageUrl'],
489 'googleRecaptcha' => Licence\Licence::isFeatureEnabledWithLicense(
490 'recaptcha',
491 $this->getSetting('featuresIntegrations', 'recaptcha')
492 ) &&
493 $this->getSetting('roles', 'customerCabinet')['googleRecaptcha'] &&
494 $this->getSetting('general', 'googleRecaptcha')['siteKey'] &&
495 $this->getSetting('general', 'googleRecaptcha')['secret'],
496 ],
497 'providerCabinet' => [
498 'loginEnabled' => $this->getSetting('roles', 'providerCabinet')['loginEnabled'],
499 'tokenValidTime' => $this->getSetting('roles', 'providerCabinet')['tokenValidTime'],
500 'googleRecaptcha' => Licence\Licence::isFeatureEnabledWithLicense(
501 'recaptcha',
502 $this->getSetting('featuresIntegrations', 'recaptcha')
503 ) &&
504 $this->getSetting('roles', 'providerCabinet')['googleRecaptcha'] &&
505 $this->getSetting('general', 'googleRecaptcha')['siteKey'] &&
506 $this->getSetting('general', 'googleRecaptcha')['secret'],
507 ],
508 'providerBadges' => Licence\Licence::isFeatureEnabledWithLicense(
509 'employeeBadge',
510 $this->getSetting('featuresIntegrations', 'employeeBadge')
511 ) ? $this->getSetting('roles', 'providerBadges') : [],
512 'limitPerCustomerService' => $this->getSetting('roles', 'limitPerCustomerService'),
513 'limitPerCustomerPackage' => $this->getSetting('roles', 'limitPerCustomerPackage'),
514 'limitPerCustomerEvent' => $this->getSetting('roles', 'limitPerCustomerEvent'),
515 'limitPerEmployee' => $this->getSetting('roles', 'limitPerEmployee'),
516 ],
517 'customization' => $this->getCategorySettings('customization'),
518 'customizedData' => $this->getCategorySettings('customizedData'),
519 'appointments' => $this->getCategorySettings('appointments'),
520 'slotDateConstraints' => [
521 'minDate' => DateTimeService::getNowDateTimeObject()
522 ->modify(
523 "+{$this->getSetting('general', 'minimumTimeRequirementPriorToBooking')} seconds"
524 )
525 ->format('Y-m-d H:i:s'),
526 'maxDate' => DateTimeService::getNowDateTimeObject()
527 ->modify(
528 "+{$this->getSetting('general', 'numberOfDaysAvailableForBooking')} day"
529 )
530 ->format('Y-m-d H:i:s')
531 ],
532 'company' => [
533 'email' => $this->getSetting('company', 'email'),
534 'phone' => $this->getSetting('company', 'phone'),
535 ],
536 'pageColumnSettings' => $this->getCategorySettings('pageColumnSettings'),
537 'featuresIntegrations' => Licence\Licence::filterFeaturesByLicense(
538 $this->getCategorySettings('featuresIntegrations')
539 ),
540 ];
541 }
542
543 public function getBackendSettings()
544 {
545 $capabilities = [];
546
547 if (is_admin()) {
548 $entities = [
549 'appointments',
550 'events',
551 'customers',
552 'employees',
553 'services',
554 'packages',
555 'resources',
556 'finance',
557 'coupons',
558 'taxes',
559 'locations',
560 'custom_fields',
561 'notifications',
562 'settings',
563 ];
564
565 foreach ($entities as $entity) {
566 $capabilities = array_merge(
567 $capabilities,
568 [
569 'canRead' . ucfirst($entity) => current_user_can('amelia_read_' . $entity),
570 'canReadOthers' . ucfirst($entity) => current_user_can('amelia_read_others_' . $entity),
571 'canWrite' . ucfirst($entity) => current_user_can('amelia_write_' . $entity),
572 'canWriteOthers' . ucfirst($entity) => current_user_can('amelia_write_others_' . $entity),
573 'canDelete' . ucfirst($entity) => current_user_can('amelia_delete_' . $entity),
574 'canWriteStatus' . ucfirst($entity) => current_user_can('amelia_write_status_' . $entity),
575 ]
576 );
577 }
578 }
579
580 $phoneCountryCode = $this->getSetting('general', 'phoneDefaultCountryCode');
581 $ipLocateApyKey = $this->getSetting('general', 'ipLocateApiKey');
582
583 $wpUser = wp_get_current_user();
584
585 $userType = 'customer';
586
587 if (in_array('administrator', $wpUser->roles, true) || is_super_admin($wpUser->ID)) {
588 $userType = 'admin';
589 } elseif (in_array('wpamelia-manager', $wpUser->roles, true)) {
590 $userType = 'manager';
591 } elseif (in_array('wpamelia-provider', $wpUser->roles, true)) {
592 $userType = 'provider';
593 }
594
595 return [
596 'capabilities' => $capabilities,
597 'activation' => [
598 'licence' => $this->getSetting('activation', 'licence'),
599 'stash' => $this->getSetting('activation', 'stash'),
600 'hideUnavailableFeatures' => $this->getSetting('activation', 'hideUnavailableFeatures'),
601 'hideTipsAndSuggestions' => $this->getSetting('activation', 'hideTipsAndSuggestions'),
602 ],
603 'appleCalendar' => [
604 'active' => Licence\Licence::isFeatureEnabledWithLicense(
605 'appleCalendar',
606 $this->getSetting('featuresIntegrations', 'appleCalendar')
607 ) &&
608 $this->getSetting('appleCalendar', 'clientID') &&
609 $this->getSetting('appleCalendar', 'clientSecret'),
610 ],
611 'appointments' => [
612 'cartPlaceholders' => $this->getSetting('appointments', 'cartPlaceholders'),
613 'cartPlaceholdersCustomer' => $this->getSetting('appointments', 'cartPlaceholdersCustomer'),
614 'cartPlaceholdersCustomerSms' => $this->getSetting(
615 'appointments',
616 'cartPlaceholdersCustomerSms'
617 ),
618 'cartPlaceholdersSms' => $this->getSetting('appointments', 'cartPlaceholdersSms'),
619 'groupAppointmentPlaceholder' => $this->getSetting(
620 'appointments',
621 'groupAppointmentPlaceholder'
622 ),
623 'groupAppointmentPlaceholderCustomer' => $this->getSetting(
624 'appointments',
625 'groupAppointmentPlaceholderCustomer'
626 ),
627 'groupAppointmentPlaceholderSms' => $this->getSetting(
628 'appointments',
629 'groupAppointmentPlaceholderSms'
630 ),
631 'groupEventPlaceholder' => $this->getSetting('appointments', 'groupEventPlaceholder'),
632 'groupEventPlaceholderCustomer' => $this->getSetting(
633 'appointments',
634 'groupEventPlaceholderCustomer'
635 ),
636 'groupEventPlaceholderSms' => $this->getSetting('appointments', 'groupEventPlaceholderSms'),
637 'packagePlaceholders' => $this->getSetting('appointments', 'packagePlaceholders'),
638 'packagePlaceholdersCustomer' => $this->getSetting(
639 'appointments',
640 'packagePlaceholdersCustomer'
641 ),
642 'packagePlaceholdersCustomerSms' => $this->getSetting(
643 'appointments',
644 'packagePlaceholdersCustomerSms'
645 ),
646 'packagePlaceholdersSms' => $this->getSetting('appointments', 'packagePlaceholdersSms'),
647 'recurringPlaceholders' => $this->getSetting('appointments', 'recurringPlaceholders'),
648 'recurringPlaceholdersCustomer' => $this->getSetting(
649 'appointments',
650 'recurringPlaceholdersCustomer'
651 ),
652 'recurringPlaceholdersCustomerSms' => $this->getSetting(
653 'appointments',
654 'recurringPlaceholdersCustomerSms'
655 ),
656 'recurringPlaceholdersSms' => $this->getSetting('appointments', 'recurringPlaceholdersSms'),
657 'waitingListAppointments' => $this->getSetting('appointments', 'waitingListAppointments'),
658 ],
659 'daysOff' => $this->getCategorySettings('daysOff'),
660 'events' => [
661 'waitingListEvents' => [
662 'addingMethod' => $this->getSetting('appointments', 'waitingListEvents')['addingMethod'],
663 ],
664 ],
665 'featuresIntegrations' => Licence\Licence::filterFeaturesByLicense(
666 $this->getCategorySettings('featuresIntegrations')
667 ),
668 'general' => [
669 'customFieldsBackendValidation' => $this->getSetting('general', 'customFieldsBackendValidation'),
670 'customersFilterLimit' => $this->getSetting('general', 'customersFilterLimit'),
671 'defaultAppointmentStatus' => $this->getSetting('general', 'defaultAppointmentStatus'),
672 'gMapApiKey' => $this->getSetting('general', 'gMapApiKey'),
673 'minimumTimeRequirementPriorToBooking' => $this->getSetting(
674 'general',
675 'minimumTimeRequirementPriorToBooking'
676 ),
677 'minimumTimeRequirementPriorToCanceling' => $this->getSetting(
678 'general',
679 'minimumTimeRequirementPriorToCanceling'
680 ),
681 'minimumTimeRequirementPriorToRescheduling' => $this->getSetting(
682 'general',
683 'minimumTimeRequirementPriorToRescheduling'
684 ),
685 'numberOfDaysAvailableForBooking' => $this->getSetting(
686 'general',
687 'numberOfDaysAvailableForBooking'
688 ),
689 'phoneDefaultCountryCode' => $phoneCountryCode === 'auto' ? $this->locationService->getCurrentLocationCountryIso(
690 $ipLocateApyKey
691 ) : $phoneCountryCode,
692 'redirectUrlAfterAppointment' => $this->getSetting(
693 'general',
694 'redirectUrlAfterAppointment'
695 ),
696 'sortingPackages' => $this->getSetting('general', 'sortingPackages'),
697 'sortingServices' => $this->getSetting('general', 'sortingServices'),
698 'timeSlotLength' => $this->getSetting('general', 'timeSlotLength'),
699 'usedLanguages' => $this->getSetting('general', 'usedLanguages'),
700 ],
701 'googleCalendar' => [
702 'active' => Licence\Licence::isFeatureEnabledWithLicense(
703 'googleCalendar',
704 $this->getSetting('featuresIntegrations', 'googleCalendar')
705 ) &&
706 (($this->getSetting('googleCalendar', 'clientID') &&
707 $this->getSetting('googleCalendar', 'clientSecret')) ||
708 $this->getSetting('googleCalendar', 'accessToken')),
709 'googleMeet' => $this->getSetting('googleCalendar', 'enableGoogleMeet'),
710 'hasAccessToken' => !empty($this->getSetting('googleCalendar', 'accessToken')) &&
711 $this->getSetting('googleCalendar', 'accessToken') !== 'null',
712
713 ],
714 'lessonSpace' => [
715 'active' =>
716 Licence\Licence::isFeatureEnabledWithLicense(
717 'lessonSpace',
718 $this->getSetting('featuresIntegrations', 'lessonSpace')
719 ) && $this->getSetting('lessonSpace', 'apiKey')
720 ],
721 'socialLogin' => [
722 'googleLoginEnabled' => Licence\Licence::isFeatureEnabledWithLicense(
723 'googleSocialLogin',
724 $this->getSetting('featuresIntegrations', 'googleSocialLogin')
725 ),
726 'facebookLoginEnabled' => Licence\Licence::isFeatureEnabledWithLicense(
727 'facebookSocialLogin',
728 $this->getSetting('featuresIntegrations', 'facebookSocialLogin')
729 ),
730 'facebookAppId' => $this->getSetting('socialLogin', 'facebookAppId'),
731 'facebookCredentialsEnabled' => $this->getSetting('socialLogin', 'facebookAppId') &&
732 $this->getSetting('socialLogin', 'facebookAppSecret'),
733 ],
734 'mailchimp' => [
735 'subscribeFieldVisible' =>
736 Licence\Licence::isFeatureEnabledWithLicense(
737 'mailchimp',
738 $this->getSetting('featuresIntegrations', 'mailchimp')
739 ) &&
740 !empty($this->getSetting('mailchimp', 'accessToken')) &&
741 !empty($this->getSetting('mailchimp', 'list')) &&
742 !empty($this->getSetting('mailchimp', 'server')),
743 'checkedByDefault' => $this->getSetting('mailchimp', 'checkedByDefault'),
744 ],
745 'notifications' => [
746 'sendAllCF' => $this->getSetting('notifications', 'sendAllCF'),
747 'senderEmail' => $this->getSetting('notifications', 'senderEmail'),
748 'sms' => [
749 'signedIn' => $this->getSetting('notifications', 'smsSignedIn'),
750 ],
751 'whatsApp' => [
752 'active' => Licence\Licence::isFeatureEnabledWithLicense(
753 'whatsapp',
754 $this->getSetting('featuresIntegrations', 'whatsapp')
755 )
756 && $this->getSetting('notifications', 'whatsAppPhoneID')
757 && $this->getSetting('notifications', 'whatsAppAccessToken')
758 && $this->getSetting('notifications', 'whatsAppBusinessID'),
759 'phoneId' => $this->getSetting('notifications', 'whatsAppPhoneID'),
760 ],
761 ],
762 'outlookCalendar' => [
763 'active' => Licence\Licence::isFeatureEnabledWithLicense(
764 'outlookCalendar',
765 $this->getSetting('featuresIntegrations', 'outlookCalendar')
766 ) &&
767 (($this->getSetting('outlookCalendar', 'clientID') &&
768 $this->getSetting('outlookCalendar', 'clientSecret')) ||
769 $this->getSetting('outlookCalendar', 'accessToken')),
770 'microsoftTeams' => $this->getSetting('outlookCalendar', 'enableMicrosoftTeams'),
771 'hasAccessToken' => !empty($this->getSetting('outlookCalendar', 'accessToken')) &&
772 $this->getSetting('outlookCalendar', 'accessToken') !== 'null',
773
774 ],
775 'pageColumnSettings' => $this->getCategorySettings('pageColumnSettings'),
776 'payments' => [
777 'barion' => [
778 'active' =>
779 Licence\Licence::isFeatureEnabledWithLicense(
780 'barion',
781 $this->getSetting('featuresIntegrations', 'barion')
782 ) &&
783 $this->getSetting('payments', 'barion')['enabled'] &&
784 (($this->getSetting('payments', 'barion')['sandboxMode'] && $this->getSetting(
785 'payments',
786 'barion'
787 )['sandboxPOSKey'] && $this->getSetting('payments', 'barion')['payeeEmail']) ||
788 (! $this->getSetting('payments', 'barion')['sandboxMode'] && $this->getSetting(
789 'payments',
790 'barion'
791 )['livePOSKey'] && $this->getSetting('payments', 'barion')['payeeEmail']))
792 ],
793 'currency' => $this->getSetting('payments', 'symbol'),
794 'defaultPaymentMethod' => $this->getSetting('payments', 'defaultPaymentMethod'),
795 'mollie' => [
796 'active' =>
797 Licence\Licence::isFeatureEnabledWithLicense(
798 'mollie',
799 $this->getSetting('featuresIntegrations', 'mollie')
800 ) &&
801 $this->getSetting('payments', 'mollie')['enabled'] &&
802 (($this->getSetting('payments', 'mollie')['testMode'] && $this->getSetting(
803 'payments',
804 'mollie'
805 )['testApiKey']) ||
806 (! $this->getSetting('payments', 'mollie')['testMode'] && $this->getSetting(
807 'payments',
808 'mollie'
809 )['liveApiKey']))
810 ],
811 'onSite' => $this->getSetting('payments', 'onSite'),
812 'taxes' => array_merge(
813 $this->getSetting('payments', 'taxes'),
814 [
815 'enabled' => Licence\Licence::isFeatureEnabledWithLicense(
816 'tax',
817 $this->getSetting('featuresIntegrations', 'tax')
818 )
819 ]
820 ),
821 'paymentLinks' => [
822 'enabled' => $this->getSetting('payments', 'paymentLinks')['enabled'],
823 'changeBookingStatus' => $this->getSetting('payments', 'paymentLinks')['changeBookingStatus'],
824 'redirectUrl' => $this->getSetting('payments', 'paymentLinks')['redirectUrl']
825 ],
826 'payPal' => [
827 'active' =>
828 Licence\Licence::isFeatureEnabledWithLicense(
829 'payPal',
830 $this->getSetting('featuresIntegrations', 'payPal')
831 ) &&
832 $this->getSetting('payments', 'payPal')['enabled'] &&
833 (($this->getSetting('payments', 'payPal')['sandboxMode'] && $this->getSetting(
834 'payments',
835 'payPal'
836 )['testApiClientId'] && $this->getSetting('payments', 'payPal')['testApiSecret']) ||
837 (! $this->getSetting('payments', 'payPal')['sandboxMode'] && $this->getSetting(
838 'payments',
839 'payPal'
840 )['liveApiClientId'] && $this->getSetting('payments', 'payPal')['liveApiSecret']))
841 ],
842 'priceNumberOfDecimals' => $this->getSetting('payments', 'priceNumberOfDecimals'),
843 'priceSeparator' => $this->getSetting('payments', 'priceSeparator'),
844 'priceSymbolPosition' => $this->getSetting('payments', 'priceSymbolPosition'),
845 'razorpay' => [
846 'active' =>
847 Licence\Licence::isFeatureEnabledWithLicense(
848 'razorpay',
849 $this->getSetting('featuresIntegrations', 'razorpay')
850 ) &&
851 $this->getSetting('payments', 'razorpay')['enabled'] &&
852 (($this->getSetting('payments', 'razorpay')['testMode'] && $this->getSetting(
853 'payments',
854 'razorpay'
855 )['testKeyId'] && $this->getSetting('payments', 'razorpay')['testKeySecret']) ||
856 (! $this->getSetting('payments', 'razorpay')['testMode'] && $this->getSetting(
857 'payments',
858 'razorpay'
859 )['liveKeyId'] && $this->getSetting('payments', 'razorpay')['liveKeySecret']))
860 ],
861 'stripe' => [
862 'active' =>
863 Licence\Licence::isFeatureEnabledWithLicense(
864 'stripe',
865 $this->getSetting('featuresIntegrations', 'stripe')
866 ) &&
867 $this->getSetting('payments', 'stripe')['enabled'] &&
868 (($this->getSetting('payments', 'stripe')['testMode'] && $this->getSetting(
869 'payments',
870 'stripe'
871 )['testPublishableKey'] && $this->getSetting('payments', 'stripe')['testSecretKey']) ||
872 (! $this->getSetting('payments', 'stripe')['testMode'] && $this->getSetting(
873 'payments',
874 'stripe'
875 )['livePublishableKey'] && $this->getSetting('payments', 'stripe')['liveSecretKey'])),
876 'connect' => $this->getSetting('payments', 'stripe')['connect'],
877 ],
878 'square' => [
879 'active' =>
880 Licence\Licence::isFeatureEnabledWithLicense(
881 'square',
882 $this->getSetting('featuresIntegrations', 'square')
883 ) &&
884 $this->getSetting('payments', 'square')['enabled'] &&
885 $this->getSetting('payments', 'square')['accessToken'] &&
886 $this->getSetting('payments', 'square')['locationId']
887 ],
888 'wc' => [
889 'active' => Licence\Licence::isFeatureEnabledWithLicense(
890 'wc',
891 $this->getSetting('featuresIntegrations', 'wc')
892 ) &&
893 $this->getSetting('payments', 'wc')['enabled'],
894 'productId' => $this->getSetting('payments', 'wc')['productId'],
895 ]
896 ],
897
898 'role' => $userType,
899 'roles' => [
900 'providerBadges' => Licence\Licence::isFeatureEnabledWithLicense(
901 'employeeBadge',
902 $this->getSetting('featuresIntegrations', 'employeeBadge')
903 ) ? $this->getSetting('roles', 'providerBadges') : [],
904 'allowCustomerReschedule' => $this->getSetting('roles', 'allowCustomerReschedule'),
905 'allowConfigureSchedule' => $this->getSetting('roles', 'allowConfigureSchedule'),
906 'allowConfigureDaysOff' => $this->getSetting('roles', 'allowConfigureDaysOff'),
907 'allowConfigureSpecialDays' => $this->getSetting('roles', 'allowConfigureSpecialDays'),
908 'allowConfigureServices' => $this->getSetting('roles', 'allowConfigureServices'),
909 'allowWriteAppointments' => $this->getSetting('roles', 'allowWriteAppointments'),
910 'allowWriteEvents' => $this->getSetting('roles', 'allowWriteEvents'),
911 ],
912 'weekSchedule' => $this->getCategorySettings('weekSchedule'),
913 'wordpress' => [
914 'dateFormat' => $this->getSetting('wordpress', 'dateFormat'),
915 'locale' => AMELIA_LOCALE,
916 'startOfWeek' => (int)$this->getSetting('wordpress', 'startOfWeek'),
917 'timeFormat' => $this->getSetting('wordpress', 'timeFormat'),
918 'timezone' => $this->getSetting('wordpress', 'timeZoneString'),
919 'gmtOffset' => $this->getSetting('wordpress', 'gmtOffset'),
920 ],
921 'zoom' => [
922 'active' => (
923 Licence\Licence::isFeatureEnabledWithLicense(
924 'zoom',
925 $this->getSetting('featuresIntegrations', 'zoom')
926 ) &&
927 $this->getSetting('zoom', 'accountId') &&
928 $this->getSetting('zoom', 'clientId') &&
929 $this->getSetting('zoom', 'clientSecret')
930 )
931 ],
932 ];
933 }
934
935 /**
936 * @param $settingCategoryKey
937 * @param $settingKey
938 * @param $settingValue
939 *
940 * @return mixed|void
941 */
942 public function setSetting($settingCategoryKey, $settingKey, $settingValue)
943 {
944 $this->settingsCache[$settingCategoryKey][$settingKey] = $settingValue;
945 $settingsCopy = $this->settingsCache;
946
947 unset($settingsCopy['wordpress']);
948 update_option('amelia_settings', json_encode($settingsCopy));
949 }
950
951 /**
952 * @param $settingCategoryKey
953 * @param $settingValues
954 *
955 * @return mixed|void
956 */
957 public function setCategorySettings($settingCategoryKey, $settingValues)
958 {
959 $this->settingsCache[$settingCategoryKey] = $settingValues;
960 $settingsCopy = $this->settingsCache;
961
962 unset($settingsCopy['wordpress']);
963 update_option('amelia_settings', json_encode($settingsCopy));
964 }
965
966 /**
967 * @param array $settings
968 *
969 * @return mixed|void
970 */
971 public function setAllSettings($settings)
972 {
973 foreach ($settings as $settingCategoryKey => $settingValues) {
974 $this->settingsCache[$settingCategoryKey] = $settingValues;
975 }
976 $settingsCopy = $this->settingsCache;
977
978 Licence\DataModifier::restoreSettings($settingsCopy, self::getSavedSettings());
979
980 if (get_option('amelia_show_wpdt_promo') === false) {
981 update_option('amelia_show_wpdt_promo', 'yes');
982 }
983
984 unset($settingsCopy['wordpress']);
985 update_option('amelia_settings', json_encode($settingsCopy));
986 }
987 }
988