PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.2
Booking for Appointments and Events Calendar – Amelia v2.2
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 / ameliabooking.php
ameliabooking Last commit date
Licensing 2 years ago extensions 2 months ago languages 2 months ago public 2 months ago redesign 2 months ago src 2 months ago v3 2 months ago vendor 2 months ago view 2 months ago .babelrc 6 years ago ameliabooking.php 2 months ago readme.txt 2 months ago
ameliabooking.php
735 lines
1 <?php
2 /*
3 Plugin Name: Amelia
4 Plugin URI: https://wpamelia.com/
5 Description: Amelia is a simple yet powerful automated booking specialist, working 24/7 to make sure your customers can make appointments and events even while you sleep!
6 Version: 2.2
7 Author: Melograno Ventures
8 Author URI: https://melograno.io/
9 Text Domain: ameliabooking
10 Domain Path: /languages
11 License: GPLv2 or later
12 License URI: http://www.gnu.org/licenses/gpl-2.0.html
13 */
14
15 namespace AmeliaBooking;
16
17 use AmeliaBooking\Domain\Services\Settings\SettingsService;
18 use AmeliaBooking\Infrastructure\Common\Container;
19 use AmeliaBooking\Infrastructure\Licence\LicenceConstants;
20 use AmeliaBooking\Infrastructure\Routes\Routes;
21 use AmeliaBooking\Infrastructure\Services\Payment\SquareService;
22 use AmeliaBooking\Infrastructure\WP\ButtonService\ButtonService;
23 use AmeliaBooking\Infrastructure\WP\config\Menu;
24 use AmeliaBooking\Infrastructure\WP\Elementor\ElementorBlock;
25 use AmeliaBooking\Infrastructure\WP\ErrorService\ErrorService;
26 use AmeliaBooking\Infrastructure\WP\GutenbergBlock\AmeliaBookingGutenbergBlock;
27 use AmeliaBooking\Infrastructure\WP\GutenbergBlock\AmeliaStepBookingGutenbergBlock;
28 use AmeliaBooking\Infrastructure\WP\GutenbergBlock\AmeliaCatalogBookingGutenbergBlock;
29 use AmeliaBooking\Infrastructure\WP\GutenbergBlock\AmeliaCatalogGutenbergBlock;
30 use AmeliaBooking\Infrastructure\WP\GutenbergBlock\AmeliaEventsGutenbergBlock;
31 use AmeliaBooking\Infrastructure\WP\GutenbergBlock\AmeliaEventsListBookingGutenbergBlock;
32 use AmeliaBooking\Infrastructure\WP\Integrations\WooCommerce\StarterWooCommerceService;
33 use AmeliaBooking\Infrastructure\WP\SettingsService\SettingsStorage;
34 use AmeliaBooking\Infrastructure\WP\Translations\BackendStrings;
35 use AmeliaBooking\Infrastructure\WP\UserRoles\UserRoles;
36 use AmeliaBooking\Infrastructure\WP\WPMenu\Submenu;
37 use AmeliaBooking\Infrastructure\WP\WPMenu\SubmenuPageHandler;
38 use AmeliaBooking\Infrastructure\WP\Compatibility\LiteSpeedCacheCompatibility;
39 use AmeliaBooking\Infrastructure\WP\WPMenu\AdminBarMenu;
40 use Exception;
41 use Slim\App;
42 use AmeliaBooking\Infrastructure\Licence;
43
44 // No direct access
45 defined('ABSPATH') or die('No script kiddies please!');
46
47 if (!defined('AMELIA_DOMAIN')) {
48 define('AMELIA_DOMAIN', 'ameliabooking');
49 }
50
51 // Const for path root
52 if (!defined('AMELIA_PATH')) {
53 define('AMELIA_PATH', __DIR__);
54 }
55
56 // Const for uploads path
57 if (!defined('AMELIA_UPLOADS_PATH')) {
58 $uploadDir = wp_upload_dir();
59 define('AMELIA_UPLOADS_PATH', $uploadDir['basedir']);
60 }
61
62 // Const for uploads url
63 if (!defined('AMELIA_UPLOADS_URL')) {
64 $uploadUrl = wp_upload_dir();
65 define('AMELIA_UPLOADS_URL', set_url_scheme($uploadUrl['baseurl']));
66 }
67
68 // Const for uploads url
69 if (!defined('AMELIA_UPLOADS_FILES_URL')) {
70 define('AMELIA_UPLOADS_FILES_URL', AMELIA_UPLOADS_URL . '/amelia/files/');
71 }
72
73 // Const for uploads files path
74 if (!defined('AMELIA_UPLOADS_FILES_PATH')) {
75 define('AMELIA_UPLOADS_FILES_PATH', AMELIA_UPLOADS_PATH . '/amelia/files/');
76 }
77
78 // Const for uploads files path
79 if (!defined('AMELIA_UPLOADS_FILES_PATH_USE')) {
80 define('AMELIA_UPLOADS_FILES_PATH_USE', true);
81 }
82
83 // Const for URL root
84 if (!defined('AMELIA_URL')) {
85 define('AMELIA_URL', plugin_dir_url(__FILE__));
86 }
87
88 if (!defined('AMELIA_HOME_URL')) {
89 define('AMELIA_HOME_URL', get_home_url());
90 }
91
92 // Const for URL Actions identifier
93 if (!defined('AMELIA_ACTION_SLUG')) {
94 define('AMELIA_ACTION_SLUG', 'action=wpamelia_api&call=');
95 }
96
97 // Const for URL Actions identifier
98 if (!defined('AMELIA_ACTION_URL')) {
99 define('AMELIA_ACTION_URL', admin_url('admin-ajax.php', '') . '?' . AMELIA_ACTION_SLUG);
100 }
101
102 // Const for URL Actions identifier
103 if (!defined('AMELIA_PAGE_URL')) {
104 define('AMELIA_PAGE_URL', get_site_url() . '/wp-admin/admin.php?page=');
105 }
106
107 // Const for URL Actions identifier
108 if (!defined('AMELIA_LOGIN_URL')) {
109 define('AMELIA_LOGIN_URL', get_site_url() . '/wp-login.php?redirect_to=');
110 }
111
112 // Const for Amelia version
113 if (!defined('AMELIA_VERSION')) {
114 define('AMELIA_VERSION', '2.2');
115 }
116
117 // Const for site URL
118 if (!defined('AMELIA_SITE_URL')) {
119 define('AMELIA_SITE_URL', get_site_url());
120 }
121
122 // Const for plugin basename
123 if (!defined('AMELIA_PLUGIN_SLUG')) {
124 define('AMELIA_PLUGIN_SLUG', plugin_basename(__FILE__));
125 }
126
127 // Const for Amelia SMS API
128 if (!defined('AMELIA_SMS_API_URL')) {
129 define('AMELIA_SMS_API_URL', 'https://smsapi.wpamelia.com/');
130 define('AMELIA_SMS_VENDOR_ID', 36082);
131 define('AMELIA_SMS_IS_SANDBOX', false);
132 define('AMELIA_SMS_PRODUCT_ID_10', 595657);
133 define('AMELIA_SMS_PRODUCT_ID_20', 595658);
134 define('AMELIA_SMS_PRODUCT_ID_50', 595659);
135 define('AMELIA_SMS_PRODUCT_ID_100', 595660);
136 define('AMELIA_SMS_PRODUCT_ID_200', 595661);
137 define('AMELIA_SMS_PRODUCT_ID_500', 595662);
138 }
139
140 if (!defined('AMELIA_STORE_API_URL')) {
141 define('AMELIA_STORE_API_URL', 'https://store.melograno.io/api/');
142 }
143
144 if (!defined('AMELIA_DEV')) {
145 define('AMELIA_DEV', false);
146 }
147
148 if (!defined('AMELIA_PRODUCTION')) {
149 define('AMELIA_PRODUCTION', true);
150 }
151
152 if (!defined('AMELIA_NGROK_URL')) {
153 define('AMELIA_NGROK_URL', 'nonmelodiously-barnlike-anika.ngrok-free.dev');
154 }
155
156 if (!defined('AMELIA_MIDDLEWARE_URL')) {
157 define('AMELIA_MIDDLEWARE_URL', 'https://middleware.wpamelia.com/');
158 }
159
160 if (!defined('AMELIA_MAILCHIMP_CLIENT_ID')) {
161 define('AMELIA_MAILCHIMP_CLIENT_ID', '459163389015');
162 }
163
164 require_once AMELIA_PATH . '/vendor/autoload.php';
165
166
167 /**
168 * @noinspection AutoloadingIssuesInspection
169 *
170 * Class Plugin
171 *
172 * @package AmeliaBooking
173 *
174 * @phpcs:ignoreFile
175 * @SuppressWarnings(PHPMD)
176 */
177 class Plugin
178 {
179
180 /**
181 * API Call
182 *
183 * @throws \InvalidArgumentException
184 */
185 public static function wpAmeliaApiCall()
186 {
187 try {
188 /** @var Container $container */
189 $container = require AMELIA_PATH . '/src/Infrastructure/ContainerConfig/container.php';
190
191 $app = new App($container);
192
193 // Initialize all API routes
194 Routes::routes($app, $container);
195
196 $app->run();
197
198 exit();
199 } catch (Exception $e) {
200 echo 'ERROR: ' . esc_html($e->getMessage());
201 }
202 }
203
204 static function square_weekly_token_refresh( $schedules ) {
205 $schedules['weekly'] = array(
206 'interval' => 604800,
207 'display' => __('Add weekly cron to refresh square access token every 7 days')
208 );
209 return $schedules;
210 }
211
212 /**
213 * Initialize the plugin
214 */
215 public static function init()
216 {
217 $settingsService = new SettingsService(new SettingsStorage());
218
219 // Initialize LiteSpeed Cache compatibility
220 LiteSpeedCacheCompatibility::init();
221
222 self::weglotConflict($settingsService, true);
223
224 load_plugin_textdomain(AMELIA_DOMAIN, false, plugin_basename(__DIR__) . '/languages/' . AMELIA_LOCALE . '/');
225
226 self::weglotConflict($settingsService, false);
227
228 if (StarterWooCommerceService::isEnabled()) {
229 if (!empty($settingsService->getCategorySettings('payments')['wc']['dashboard'])) {
230 add_filter('woocommerce_prevent_admin_access', '__return_false');
231 }
232
233 if (!empty($settingsService->getCategorySettings('payments')['wc']['enabled'])) {
234 try {
235 StarterWooCommerceService::init($settingsService);
236 } catch (ContainerException $e) {
237 }
238 } else {
239 StarterWooCommerceService::setContainer(require AMELIA_PATH . '/src/Infrastructure/ContainerConfig/container.php');
240 StarterWooCommerceService::$settingsService = $settingsService;
241
242 add_filter('woocommerce_after_order_itemmeta', [StarterWooCommerceService::class, 'orderItemMeta'], 10, 3);
243 }
244 }
245
246 if (!empty($settingsService->getCategorySettings('payments')['square']['enabled']) &&
247 !empty($settingsService->getCategorySettings('payments')['square']['accessToken'])) {
248 add_filter( 'cron_schedules', [self::class, 'square_weekly_token_refresh'] );
249
250 if ( ! wp_next_scheduled( 'amelia_square_access_token_refresh' ) ) {
251 wp_schedule_event( time(), 'weekly', 'amelia_square_access_token_refresh' );
252 }
253
254 /** @var Container $container */
255 $container = require AMELIA_PATH . '/src/Infrastructure/ContainerConfig/container.php';
256
257 /** @var SquareService $squareService */
258 $squareService = $container->get('infrastructure.payment.square.service');
259
260 add_action( 'amelia_square_access_token_refresh', [$squareService, 'refreshAccessToken'] );
261 }
262
263 $ameliaRole = UserRoles::getUserAmeliaRole(wp_get_current_user());
264
265 // Register Gutenberg blocks for rendering on frontend (works for all users, logged in or not)
266 AmeliaStepBookingGutenbergBlock::init();
267 AmeliaCatalogBookingGutenbergBlock::init();
268 AmeliaBookingGutenbergBlock::init();
269 AmeliaCatalogGutenbergBlock::init();
270 AmeliaEventsGutenbergBlock::init();
271 AmeliaEventsListBookingGutenbergBlock::init();
272
273 // Init menu if user is logged in with amelia role
274 if (in_array($ameliaRole, ['admin', 'manager', 'provider', 'customer'])) {
275 if ($ameliaRole === 'admin') {
276 ErrorService::setNotices();
277 }
278
279 // Add TinyMCE button for shortcode generator
280 ButtonService::renderButton();
281
282 add_filter('block_categories_all', array('AmeliaBooking\Plugin', 'addAmeliaBlockCategory'), 10, 2);
283 add_filter('learn-press/frontend-default-scripts', array('AmeliaBooking\Plugin', 'learnPressConflict'));
284 }
285
286 if (!is_admin()) {
287 add_filter('learn-press/frontend-default-scripts', array('AmeliaBooking\Plugin', 'learnPressConflict'));
288 add_shortcode('ameliabooking', array('AmeliaBooking\Infrastructure\WP\ShortcodeService\StepBookingShortcodeService', 'shortcodeHandler'));
289 add_shortcode('ameliacatalog', array('AmeliaBooking\Infrastructure\WP\ShortcodeService\CatalogBookingShortcodeService', 'shortcodeHandler'));
290 add_shortcode('ameliaevents', array('AmeliaBooking\Infrastructure\WP\ShortcodeService\EventsShortcodeService', 'shortcodeHandler'));
291 add_shortcode('ameliaeventslistbooking', array('AmeliaBooking\Infrastructure\WP\ShortcodeService\EventsListBookingShortcodeService', 'shortcodeHandler'));
292 add_shortcode('ameliastepbooking', array('AmeliaBooking\Infrastructure\WP\ShortcodeService\StepBookingShortcodeService', 'shortcodeHandler'));
293 add_shortcode('ameliacatalogbooking', array('AmeliaBooking\Infrastructure\WP\ShortcodeService\CatalogBookingShortcodeService', 'shortcodeHandler'));
294 }
295
296 if (defined('ELEMENTOR_VERSION')) {
297 ElementorBlock::get_instance();
298 }
299
300 $theme = wp_get_theme();
301
302 $theme = $theme->parent() ?: $theme;
303
304 if ($theme && strtolower($theme->get('Name')) === 'divi' || strtolower($theme->get_template()) === 'divi') {
305 $version = $theme->get('Version');
306
307 if (version_compare($version, '5.0', '<')) {
308 // Only enqueue jQuery early in Divi builder to avoid frontend conflicts
309 add_action('wp_head', function() {
310 if (function_exists('et_fb_is_enabled') && et_fb_is_enabled()) {
311 wp_enqueue_script('jquery');
312 wp_print_scripts('jquery');
313 }
314 }, 0);
315 require_once AMELIA_PATH . '/extensions/divi_amelia/divi_amelia.php';
316 } else {
317 require_once AMELIA_PATH . '/extensions/divi_5_amelia/divi-5-amelia.php';
318 }
319 }
320
321 // Load BuddyBoss integration only if feature is enabled
322 if ($settingsService->isFeatureEnabled('buddyboss')) {
323 }
324 }
325
326 /**
327 * Creating Amelia block category in Gutenberg
328 */
329 public static function addAmeliaBlockCategory($categories, $post)
330 {
331 return array_merge(
332 array(
333 array(
334 'slug' => 'amelia-blocks',
335 'title' => 'Amelia',
336 ),
337 ),
338 $categories
339 );
340 }
341
342 /**
343 * Fix for conflict with Weglot plugin
344 * @param $settingsService
345 * @param $init
346 */
347 public static function weglotConflict($settingsService, $init)
348 {
349 if (defined('AMELIA_LOCALE_FORCED') &&
350 AMELIA_LOCALE_FORCED &&
351 function_exists('weglot_get_current_language')
352 ) {
353 try {
354 if ($init && !defined('AMELIA_LOCALE')) {
355 $weglotCurrentLanguage = weglot_get_current_language();
356
357 $ameliaUsedLanguages = array_flip($settingsService->getSetting('general', 'usedLanguages'));
358
359 require_once ABSPATH . 'wp-admin/includes/translation-install.php';
360
361 global $locale;
362
363 $potentialLanguages = [];
364
365 foreach (wp_get_available_translations() as $key => $value) {
366 if (substr($key, 0, 2) === substr($weglotCurrentLanguage, 0, 2)) {
367 $potentialLanguages[] = $key;
368 }
369 }
370
371 foreach ($potentialLanguages as $potentialLanguage) {
372 if (array_key_exists($potentialLanguage, $ameliaUsedLanguages)) {
373 $locale = $potentialLanguage;
374 break;
375 }
376 }
377 } else {
378 global $locale;
379
380 $locale = AMELIA_LOCALE_FORCED;
381 }
382 } catch (\Exception $e) {
383
384 }
385 }
386 }
387
388 /**
389 * Fix for conflict with LearnPress plugin
390 */
391 public static function learnPressConflict($data)
392 {
393
394 if (has_shortcode(get_post(get_the_ID())->post_content, 'ameliabooking') ||
395 has_shortcode(get_post(get_the_ID())->post_content, 'ameliacatalog') ||
396 has_shortcode(get_post(get_the_ID())->post_content, 'ameliaevents') ||
397 has_shortcode(get_post(get_the_ID())->post_content, 'ameliaeventslistbooking') ||
398 has_shortcode(get_post(get_the_ID())->post_content, 'ameliastepbooking')
399 ) {
400 return array();
401 } else {
402 return $data;
403 }
404
405 }
406
407 public static function initMenu()
408 {
409 $settingsService = new SettingsService(new SettingsStorage());
410
411 $menuItems = new Menu($settingsService);
412
413 // Init admin menu
414 $wpMenu = new Submenu(
415 new SubmenuPageHandler($settingsService),
416 $menuItems()
417 );
418
419 $wpMenu->addOptionsPages();
420 }
421
422 public static function initAdminBar()
423 {
424 $settingsService = new SettingsService(new SettingsStorage());
425
426 add_action('admin_bar_menu', function ($wpAdminBar) use ($settingsService) {
427 $adminBarMenu = new AdminBarMenu($settingsService);
428 $adminBarMenu->addAdminBarMenu($wpAdminBar);
429 }, 100);
430 }
431
432 public static function adminInit()
433 {
434 $settingsService = new SettingsService(new SettingsStorage());
435
436 self::handleWelcomePageRedirect($settingsService);
437
438 if (AMELIA_VERSION !== $settingsService->getSetting('activation', 'version')) {
439 $settingsService->setSetting('activation', 'version', AMELIA_VERSION);
440
441 require_once ABSPATH . 'wp-admin/includes/plugin.php';
442
443 deactivate_plugins(AMELIA_PLUGIN_SLUG);
444 activate_plugin(AMELIA_PLUGIN_SLUG);
445 }
446 }
447
448 /**
449 * Handle welcome page redirect and access control
450 *
451 * @param SettingsService $settingsService
452 */
453 public static function handleWelcomePageRedirect($settingsService)
454 {
455 $currentPage = isset($_GET['page']) ? sanitize_text_field(wp_unslash($_GET['page'])) : '';
456
457 $showWelcomePage = $settingsService->getSetting('activation', 'showWelcomePage');
458 $isNewInstallation = $settingsService->getSetting('activation', 'isNewInstallation');
459
460 if (get_transient('amelia_activation_redirect') && $currentPage !== 'wpamelia-welcome') {
461 delete_transient('amelia_activation_redirect');
462
463 if ($showWelcomePage && $isNewInstallation) {
464 wp_safe_redirect(admin_url('admin.php?page=wpamelia-welcome'));
465
466 exit;
467 }
468 }
469
470 if (!$showWelcomePage && $currentPage === 'wpamelia-welcome') {
471 wp_safe_redirect(admin_url('admin.php?page=wpamelia-dashboard'));
472
473 exit;
474 }
475 }
476
477 /**
478 * @param $networkWide
479 */
480 public static function activation($networkWide)
481 {
482 load_plugin_textdomain(AMELIA_DOMAIN, false, plugin_basename(__DIR__) . '/languages/' . get_locale() . '/');
483
484 // Check PHP version
485 if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50500) {
486 deactivate_plugins(AMELIA_PLUGIN_SLUG);
487 wp_die(
488 BackendStrings::get('php_version_message'),
489 BackendStrings::get('php_version_title'),
490 array('response' => 200, 'back_link' => TRUE)
491 );
492 }
493 //Network activation
494 if ($networkWide && function_exists('is_multisite') && is_multisite()) {
495 Infrastructure\WP\InstallActions\ActivationMultisite::init();
496 }
497
498 Infrastructure\WP\InstallActions\ActivationDatabaseHook::init();
499
500 set_transient('amelia_activation_redirect', true, 30);
501 }
502
503 /**
504 * @param $dirPath
505 */
506 public static function deleteFolderContent($dirPath)
507 {
508 if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
509 $dirPath .= '/';
510 }
511
512 $files = glob($dirPath . '*', GLOB_MARK);
513
514 foreach ($files as $file) {
515 if (is_dir($file)) {
516 self::deleteFolderContent($file);
517 } else {
518 unlink($file);
519 }
520 }
521 }
522
523 /**
524 * @throws Domain\Common\Exceptions\InvalidArgumentException
525 */
526 public static function deletion()
527 {
528 $settingsService = new SettingsService(new SettingsStorage());
529
530 if ($settingsService->getSetting('activation', 'deleteTables')) {
531 //Network deletion
532 if (function_exists('is_multisite') &&
533 is_multisite()
534 ) {
535 Infrastructure\WP\InstallActions\DeletionMultisite::delete();
536 }
537
538 Infrastructure\WP\InstallActions\DeleteDatabaseHook::delete();
539
540
541 // Delete Roles
542 global $wp_roles;
543
544 $wp_roles->remove_role('wpamelia-customer');
545 $wp_roles->remove_role('wpamelia-provider');
546 $wp_roles->remove_role('wpamelia-manager');
547
548
549 // Delete Settings
550 delete_option('amelia_settings');
551 delete_option('amelia_stash');
552 delete_option('amelia_show_wpdt_promo');
553
554 // Delete Files
555 foreach (['/amelia/css', '/amelia/files/tmp', '/amelia/files', '/amelia'] as $path) {
556 if (is_dir(AMELIA_UPLOADS_PATH . $path)) {
557 self::deleteFolderContent(AMELIA_UPLOADS_PATH . $path);
558 rmdir(AMELIA_UPLOADS_PATH . $path);
559 }
560 }
561 }
562 }
563
564 /**
565 * Show WPDT promo notice
566 **/
567 public static function wpdt_dashboard_promo()
568 {
569 $wpAmeliaPage = isset($_GET['page']) ? $_GET['page'] : '';
570
571 require_once AMELIA_PATH . '/extensions/wpdt/functions.php';
572
573 if( is_admin() && (strpos($wpAmeliaPage,'wpamelia-dashboard') !== false) &&
574 amelia_installed_plugins_wpdt_promotion() &&
575 get_option( 'amelia_show_wpdt_promo' ) == 'yes'
576 ) {
577 include AMELIA_PATH . '/extensions/wpdt/promote_wpdt.php';
578 wp_enqueue_style('wdt-promo-css', AMELIA_URL . 'public/css/backend/promote_wpdt.css');
579 }
580 }
581
582 /**
583 * Remove WPDT promo notice
584 **/
585 public static function amelia_remove_wpdt_promo_notice()
586 {
587 update_option( 'amelia_show_wpdt_promo', 'no' );
588 echo json_encode( array("success") );
589 exit;
590 }
591
592 /**
593 * Hide admin notices on Amelia pages
594 **/
595 public static function hide_notices_on_amelia_pages()
596 {
597 $screen = get_current_screen();
598 if ($screen && strpos($screen->id, AMELIA_DOMAIN)) {
599 remove_action('admin_notices', 'update_nag', 3);
600 remove_action('network_admin_notices', 'update_nag', 3);
601 remove_action('admin_notices', 'maintenance_nag');
602 remove_all_actions('admin_notices');
603 remove_all_actions('all_admin_notices');
604 }
605
606 add_action('admin_notices', array('AmeliaBooking\Plugin', 'wpdt_dashboard_promo'));
607 }
608
609 /**
610 * @param array $links
611 *
612 * @return array
613 */
614 public static function addPluginActionLinks($links)
615 {
616 $primaryLinks = [
617 '<a href="' . admin_url('admin.php?page=wpamelia-dashboard') . '">View</a>',
618 '<a href="' . admin_url('admin.php?page=wpamelia-settings') . '">Settings</a>'
619 ];
620
621 if (Licence\Licence::getLicence() === LicenceConstants::LITE) {
622 $deactivate = [];
623 if (isset($links['deactivate'])) {
624 $deactivate = ['deactivate' => $links['deactivate']];
625 unset($links['deactivate']);
626 }
627
628 return array_merge(
629 $primaryLinks,
630 $links,
631 ['<a href="https://wpamelia.com/pricing/?utm_source=wp_org&utm_medium=wp_org&utm_content=plugin_row&utm_campaign=wp_org" style="color: #5951F6; font-weight: bold;" target="_blank">Get Amelia Pro</a>'],
632 $deactivate
633 );
634 }
635
636 return array_merge($primaryLinks, $links);
637 }
638
639 /**
640 * @param array $links
641 * @param string $file
642 * @param array $pluginData
643 * @param string $status
644 *
645 * @return array
646 */
647 public static function addPluginRowMeta($links, $file, $pluginData, $status)
648 {
649 if ($file !== AMELIA_PLUGIN_SLUG) {
650 return $links;
651 }
652
653 $links[] = '<a href="https://wpamelia.com/documentation/" target="_blank" rel="noopener">Docs</a>';
654
655 return $links;
656 }
657
658 public static function enqueueAngieMcpServer()
659 {
660 global $wp_version;
661 if (version_compare($wp_version, '6.5', '<')) {
662 return;
663 }
664
665 $mcpServerPath = AMELIA_PATH . '/redesign/dist/amelia-angie.js';
666 if (!file_exists($mcpServerPath)) {
667 return;
668 }
669
670 wp_enqueue_script_module(
671 'amelia-angie-mcp',
672 AMELIA_URL . 'redesign/dist/amelia-angie.js',
673 array(),
674 AMELIA_VERSION
675 );
676 }
677 }
678
679 add_action('wp_ajax_amelia_remove_wpdt_promo_notice', array('AmeliaBooking\Plugin', 'amelia_remove_wpdt_promo_notice'));
680
681 add_action('admin_head', array('AmeliaBooking\Plugin', 'hide_notices_on_amelia_pages'));
682
683 /** Redirect For Outlook Calendar */
684 if (is_admin()) {
685 add_action('wp_loaded', array('AmeliaBooking\Infrastructure\Services\Outlook\StarterOutlookCalendarService', 'handleCallback'));
686 }
687
688 /** Isolate API calls */
689 add_action('wp_ajax_wpamelia_api', array('AmeliaBooking\Plugin', 'wpAmeliaApiCall'));
690 add_action('wp_ajax_nopriv_wpamelia_api', array('AmeliaBooking\Plugin', 'wpAmeliaApiCall'));
691
692 /** Init the plugin */
693 add_action('plugins_loaded', array('AmeliaBooking\Plugin', 'init'));
694
695 add_action('init', array('AmeliaBooking\Infrastructure\WP\WPMenu\AdminBarMenu', 'enqueueScripts'));
696 add_action('init', array('AmeliaBooking\Plugin', 'initAdminBar'));
697
698 add_action('admin_init', array('AmeliaBooking\Plugin', 'adminInit'));
699
700 add_action('admin_menu', array('AmeliaBooking\Plugin', 'initMenu'));
701
702 /** Activation hooks */
703 register_activation_hook(__FILE__, array('AmeliaBooking\Plugin', 'activation'));
704 register_activation_hook(__FILE__, array('AmeliaBooking\Infrastructure\WP\InstallActions\ActivationRolesHook', 'init'));
705 register_activation_hook(__FILE__, array('AmeliaBooking\Infrastructure\WP\InstallActions\ActivationSettingsHook', 'init'));
706 register_uninstall_hook(__FILE__, array('AmeliaBooking\Plugin', 'deletion'));
707
708 /** Activation hook for new site on multisite setup */
709 add_action('wpmu_new_blog', array('AmeliaBooking\Infrastructure\WP\InstallActions\ActivationNewSiteMultisite', 'init'));
710
711 /** Define the API for updating checking */
712
713 /** Define the alternative response for information checking */
714
715 /** Add a message for unavailable auto update if plugin is not activated */
716
717 /** Add error message on plugin update if plugin is not activated */
718
719 add_filter('script_loader_tag', array('AmeliaBooking\Infrastructure\WP\ShortcodeService\StepBookingShortcodeService', 'prepareScripts') , 10, 3);
720 add_filter('style_loader_tag', array('AmeliaBooking\Infrastructure\WP\ShortcodeService\StepBookingShortcodeService', 'prepareStyles') , 10, 3);
721
722 add_filter('script_loader_tag', array('AmeliaBooking\Infrastructure\WP\ShortcodeService\EventsListBookingShortcodeService', 'prepareScripts') , 10, 3);
723 add_filter('style_loader_tag', array('AmeliaBooking\Infrastructure\WP\ShortcodeService\EventsListBookingShortcodeService', 'prepareStyles') , 10, 3);
724
725 add_filter('plugin_row_meta', array('AmeliaBooking\Plugin', 'addPluginRowMeta'), 10, 4);
726 add_filter('plugin_action_links_' . AMELIA_PLUGIN_SLUG, array('AmeliaBooking\Plugin', 'addPluginActionLinks'));
727
728 add_action( 'wp_logout', array('AmeliaBooking\Infrastructure\WP\UserService\UserService', 'logoutAmeliaUser'));
729 add_action( 'profile_update', array('AmeliaBooking\Infrastructure\WP\UserService\UserService', 'updateAmeliaUser'), 10, 3);
730 add_action( 'deleted_user', array('AmeliaBooking\Infrastructure\WP\UserService\UserService', 'removeWPUserConnection'), 10, 1);
731
732 if (function_exists('is_plugin_active') && is_plugin_active('angie/angie.php')) {
733 add_action('admin_enqueue_scripts', array('AmeliaBooking\Plugin', 'enqueueAngieMcpServer'));
734 }
735