| 1 |
<?php if (!defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
|
| 3 |
use FluentCommunity\App\Hooks\Handlers\ActivationHandler; |
| 4 |
use FluentCommunity\App\Hooks\Handlers\DeactivationHandler; |
| 5 |
use FluentCommunity\Framework\Foundation\Application; |
| 6 |
|
| 7 |
return function ($file) { |
| 8 |
|
| 9 |
$app = new Application($file); |
| 10 |
|
| 11 |
register_activation_hook($file, function () use ($app) { |
| 12 |
($app->make(ActivationHandler::class))->handle(); |
| 13 |
|
| 14 |
if (function_exists('\as_next_scheduled_action')) { |
| 15 |
if (!\as_next_scheduled_action('fluent_community_scheduled_hour_jobs')) { |
| 16 |
\as_schedule_recurring_action(time(), 3600, 'fluent_community_scheduled_hour_jobs', [], 'fluent-community', true); |
| 17 |
} |
| 18 |
|
| 19 |
if (!\as_next_scheduled_action('fluent_community_daily_jobs')) { |
| 20 |
\as_schedule_recurring_action(time(), 86400, 'fluent_community_daily_jobs', [], 'fluent-community', true); |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
}); |
| 25 |
|
| 26 |
register_deactivation_hook($file, function () use ($app) { |
| 27 |
($app->make(DeactivationHandler::class))->handle(); |
| 28 |
}); |
| 29 |
|
| 30 |
require_once FLUENT_COMMUNITY_PLUGIN_DIR . 'vendor/woocommerce/action-scheduler/action-scheduler.php'; |
| 31 |
require_once FLUENT_COMMUNITY_PLUGIN_DIR . 'app/Functions/helpers.php'; |
| 32 |
|
| 33 |
if (file_exists(FLUENT_COMMUNITY_PLUGIN_DIR . 'Modules/modules_init.php')) { |
| 34 |
require_once FLUENT_COMMUNITY_PLUGIN_DIR . 'Modules/modules_init.php'; |
| 35 |
} |
| 36 |
|
| 37 |
add_action('plugins_loaded', function () use ($app) { |
| 38 |
do_action('fluent_community/portal_loaded', $app); |
| 39 |
|
| 40 |
add_action('init', function () use ($app) { |
| 41 |
do_action('fluent_community/on_wp_init', $app); |
| 42 |
}); |
| 43 |
}); |
| 44 |
|
| 45 |
/* |
| 46 |
* A stale schema is repaired from two places. Portal render catches sites where |
| 47 |
* an admin browses the community; admin_init catches the plugin-update case, |
| 48 |
* where the first request after the new code lands is a wp-admin page and a |
| 49 |
* newly added table would otherwise not exist yet. A missing index only slows |
| 50 |
* things down, but a missing table is fatal, so the second entry point matters. |
| 51 |
*/ |
| 52 |
if (!function_exists('fluent_community_maybe_migrate_db')) { |
| 53 |
function fluent_community_maybe_migrate_db() |
| 54 |
{ |
| 55 |
$currentDBVersion = get_option('fluent_community_db_version'); |
| 56 |
|
| 57 |
if ($currentDBVersion && version_compare($currentDBVersion, FLUENT_COMMUNITY_DB_VERSION, '>=')) { |
| 58 |
return; |
| 59 |
} |
| 60 |
|
| 61 |
if (get_transient('fluent_community_db_migration_lock')) { |
| 62 |
return; |
| 63 |
} |
| 64 |
|
| 65 |
set_transient('fluent_community_db_migration_lock', 1, 5 * MINUTE_IN_SECONDS); |
| 66 |
\FluentCommunity\Database\DBMigrator::run(); |
| 67 |
update_option('fluent_community_db_version', FLUENT_COMMUNITY_DB_VERSION, false); |
| 68 |
delete_transient('fluent_community_db_migration_lock'); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
add_action('admin_init', function () { |
| 73 |
if (current_user_can('activate_plugins')) { |
| 74 |
fluent_community_maybe_migrate_db(); |
| 75 |
} |
| 76 |
}); |
| 77 |
|
| 78 |
add_action('fluent_community/portal_render_for_user', function () { |
| 79 |
if (!\FluentCommunity\App\Services\Helper::isSiteAdmin()) { |
| 80 |
return; |
| 81 |
} |
| 82 |
|
| 83 |
if (!\as_next_scheduled_action('fluent_community_scheduled_hour_jobs')) { |
| 84 |
as_schedule_recurring_action(time(), 3600, 'fluent_community_scheduled_hour_jobs', [], 'fluent-community'); |
| 85 |
} |
| 86 |
|
| 87 |
if (!\as_next_scheduled_action('fluent_community_daily_jobs')) { |
| 88 |
\as_schedule_recurring_action(time(), 86400, 'fluent_community_daily_jobs', [], 'fluent-community'); |
| 89 |
} |
| 90 |
/* |
| 91 |
* We will remove this after final release |
| 92 |
*/ |
| 93 |
fluent_community_maybe_migrate_db(); |
| 94 |
|
| 95 |
|
| 96 |
if (defined('FLUENT_COMMUNITY_PRO_VERSION')) { |
| 97 |
add_filter('fluent_community/portal_notices', function ($notices) { |
| 98 |
if (FLUENT_COMMUNITY_MIN_PRO_VERSION !== FLUENT_COMMUNITY_PRO_VERSION && version_compare(FLUENT_COMMUNITY_MIN_PRO_VERSION, FLUENT_COMMUNITY_PRO_VERSION, '>')) { |
| 99 |
$updateUrl = admin_url('plugins.php?s=fluent-community&plugin_status=all&fluent-fluent-community-pro-check-update=' . time()); |
| 100 |
$notices[] = '<div style="padding: 10px; background-color: var(--fcom-primary-bg, white);" class="error"><b>' . esc_html__('Heads UP:', 'fluent-community') . ' </b> ' . esc_html__('FluentCommunityPro Plugin needs to be updated to the latest version.', 'fluent-community') . ' <a href="' . esc_url($updateUrl) . '">' . esc_html__('Click here to update', 'fluent-community') . '</a></div>'; |
| 101 |
} |
| 102 |
return $notices; |
| 103 |
}); |
| 104 |
} |
| 105 |
|
| 106 |
}); |
| 107 |
}; |
| 108 |
|