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