run(); exit(); } catch (Exception $e) { echo 'ERROR: ' . $e->getMessage(); } } /** * Initialize the plugin */ public static function init() { // Const for path root if (!defined('AMELIA_LOCALE')) { define('AMELIA_LOCALE', get_locale()); } load_plugin_textdomain('wpamelia', false, plugin_basename(__DIR__) . '/languages/' . AMELIA_LOCALE . '/'); $settingsService = new SettingsService(new SettingsStorage()); if (class_exists('WooCommerce')) { add_filter('woocommerce_prevent_admin_access', '__return_false'); if ($settingsService->getCategorySettings('payments')['wc']['enabled']) { try { WooCommerceService::init($settingsService); } catch (ContainerException $e) { } } } $ameliaRole = UserRoles::getUserAmeliaRole(wp_get_current_user()); // Init menu if user is logged in with amelia role if (in_array($ameliaRole, ['admin', 'manager', 'provider', 'customer'])) { if ($ameliaRole === 'admin') { ErrorService::setNotices(); } $menuItems = new Menu($settingsService); // Init admin menu $wpMenu = new Submenu( new SubmenuPageHandler($settingsService), $menuItems() ); $wpMenu->init(); // Add TinyMCE button for shortcode generator ButtonService::renderButton(); // Add Gutenberg Block for shortcode generator AmeliaBookingGutenbergBlock::init(); AmeliaEventsGutenbergBlock::init(); if (!AMELIA_LITE_VERSION) { AmeliaSearchGutenbergBlock::init(); AmeliaCatalogGutenbergBlock::init(); } add_filter( 'block_categories', array('AmeliaBooking\Plugin', 'addAmeliaBlockCategory'), 10, 2); } if (!is_admin()) { add_shortcode('ameliabooking', array('AmeliaBooking\Infrastructure\WP\ShortcodeService\BookingShortcodeService', 'shortcodeHandler')); add_shortcode('ameliasearch', array('AmeliaBooking\Infrastructure\WP\ShortcodeService\SearchShortcodeService', 'shortcodeHandler')); add_shortcode('ameliacatalog', array('AmeliaBooking\Infrastructure\WP\ShortcodeService\CatalogShortcodeService', 'shortcodeHandler')); add_shortcode('ameliaevents', array('AmeliaBooking\Infrastructure\WP\ShortcodeService\EventsShortcodeService', 'shortcodeHandler')); } } /** * Creating Amelia block category in Gutenberg */ public static function addAmeliaBlockCategory ($categories, $post) { return array_merge( array( array( 'slug' => 'amelia-blocks', 'title' => 'Amelia', ), ), $categories ); } public static function adminInit() { $settingsService = new SettingsService(new SettingsStorage()); if (AMELIA_VERSION !== $settingsService->getSetting('activation', 'version')) { $settingsService->setSetting('activation', 'version', AMELIA_VERSION); require_once ABSPATH . 'wp-admin/includes/plugin.php'; deactivate_plugins(AMELIA_PLUGIN_SLUG); activate_plugin(AMELIA_PLUGIN_SLUG); } } /** * @param $networkWide */ public static function activation($networkWide) { load_plugin_textdomain('wpamelia', false, plugin_basename(__DIR__) . '/languages/' . get_locale() . '/'); // Check PHP version if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50500) { deactivate_plugins(AMELIA_PLUGIN_SLUG); wp_die( BackendStrings::getCommonStrings()['php_version_message'], BackendStrings::getCommonStrings()['php_version_title'], array('response' => 200, 'back_link' => TRUE) ); } //Network activation if ($networkWide && function_exists('is_multisite') && is_multisite()) { Infrastructure\WP\InstallActions\ActivationMultisite::init(); } Infrastructure\WP\InstallActions\ActivationDatabaseHook::init(); } } /** Isolate API calls */ add_action('wp_ajax_wpamelia_api', array('AmeliaBooking\Plugin', 'wpAmeliaApiCall')); add_action('wp_ajax_nopriv_wpamelia_api', array('AmeliaBooking\Plugin', 'wpAmeliaApiCall')); /** Init the plugin */ add_action('plugins_loaded', array('AmeliaBooking\Plugin', 'init')); add_action('admin_init', array('AmeliaBooking\Plugin', 'adminInit')); /** Activation hooks */ register_activation_hook(__FILE__, array('AmeliaBooking\Plugin', 'activation')); register_activation_hook(__FILE__, array('AmeliaBooking\Infrastructure\WP\InstallActions\ActivationRolesHook', 'init')); register_activation_hook(__FILE__, array('AmeliaBooking\Infrastructure\WP\InstallActions\ActivationSettingsHook', 'init')); /** Activation hook for new site on multisite setup */ add_action('wpmu_new_blog', array('AmeliaBooking\Infrastructure\WP\InstallActions\ActivationNewSiteMultisite', 'init')); /** Define the API for updating checking */ add_filter('pre_set_site_transient_update_plugins', array('AmeliaBooking\Infrastructure\WP\InstallActions\AutoUpdateHook', 'checkUpdate'), 21, 1); /** Define the alternative response for information checking */ add_filter('plugins_api', array('AmeliaBooking\Infrastructure\WP\InstallActions\AutoUpdateHook', 'checkInfo'), 20, 3); /** Add a message for unavailable auto update if plugin is not activated */ add_action('in_plugin_update_message-' . AMELIA_PLUGIN_SLUG, array('AmeliaBooking\Infrastructure\WP\InstallActions\AutoUpdateHook', 'addMessageOnPluginsPage')); /** Add error message on plugin update if plugin is not activated */ add_filter('upgrader_pre_download', array('AmeliaBooking\Infrastructure\WP\InstallActions\AutoUpdateHook', 'addMessageOnUpdate'), 10, 4);