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