| 1 |
<?php |
| 2 |
|
| 3 |
defined( 'ABSPATH' ) || exit; |
| 4 |
|
| 5 |
use FluentBooking\Framework\Foundation\Application; |
| 6 |
use FluentBooking\App\Hooks\Handlers\ActivationHandler; |
| 7 |
use FluentBooking\App\Hooks\Handlers\DeactivationHandler; |
| 8 |
use FluentBooking\Database\DBMigrator; |
| 9 |
|
| 10 |
return function ($file) { |
| 11 |
|
| 12 |
$app = new Application($file); |
| 13 |
|
| 14 |
register_activation_hook($file, function ($network_wide = false) use ($app) { |
| 15 |
// WordPress passes $network_wide; dropping it left every blog but the |
| 16 |
// activating one unmigrated and unscheduled on a network activation. |
| 17 |
($app->make(ActivationHandler::class))->handle($network_wide); |
| 18 |
}); |
| 19 |
|
| 20 |
register_deactivation_hook($file, function () use ($app) { |
| 21 |
($app->make(DeactivationHandler::class))->handle(); |
| 22 |
}); |
| 23 |
|
| 24 |
require_once(FLUENT_BOOKING_DIR . 'boot/action_scheduler_loader.php'); |
| 25 |
|
| 26 |
add_action('plugins_loaded', function () use ($app) { |
| 27 |
do_action('fluent_booking/loaded', $app); |
| 28 |
|
| 29 |
$currentDBVersion = get_option('fluent_booking_db_version'); |
| 30 |
|
| 31 |
if (!$currentDBVersion || version_compare($currentDBVersion, FLUENT_BOOKING_DB_VERSION, '<')) { |
| 32 |
// plugins_loaded, so every request during an upgrade reaches this. |
| 33 |
if (!get_transient('fluent_booking_db_migration_lock')) { |
| 34 |
set_transient('fluent_booking_db_migration_lock', 1, 5 * MINUTE_IN_SECONDS); |
| 35 |
|
| 36 |
DBMigrator::run(); |
| 37 |
|
| 38 |
// Stamped after the run: a failure mid-migration used to leave |
| 39 |
// the version current against a schema that never changed. |
| 40 |
update_option('fluent_booking_db_version', FLUENT_BOOKING_DB_VERSION, 'no'); |
| 41 |
|
| 42 |
delete_transient('fluent_booking_db_migration_lock'); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
if (defined('FLUENT_BOOKING_PRO_VERSION') && version_compare(FLUENT_BOOKING_MIN_PRO_VERSION, FLUENT_BOOKING_PRO_VERSION, '>')) { |
| 47 |
if (!current_user_can('manage_options')) { |
| 48 |
return; |
| 49 |
} |
| 50 |
add_filter('fluent_booking/dashboard_notices', function ($notices) { |
| 51 |
$updateUrl = admin_url('plugins.php?s=fluent-booking&plugin_status=all&fluent-booking-pro-check-update=' . time()); |
| 52 |
$notices[] = '<div class="error">' . esc_html__('FluentBookingPro plugin needs to be updated to the latest version.', 'fluent-booking') . ' <a href="' . esc_url($updateUrl) . '">' . esc_html__('Click here to update', 'fluent-booking') . '</a></div>'; |
| 53 |
return $notices; |
| 54 |
}); |
| 55 |
} |
| 56 |
}); |
| 57 |
}; |
| 58 |
|