='); } /** * Put Yatra Free and Yatra Pro at the start of the active list, in that order, so Free always boots before Pro. * * @return bool True if the option was updated. */ function yatra_normalize_yatra_plugins_active_order(): bool { if (!function_exists('get_option') || !function_exists('update_option')) { return false; } $active = get_option('active_plugins', []); if (!is_array($active) || $active === []) { return false; } $free = 'yatra/yatra.php'; $pro = 'yatra-pro/yatra-pro.php'; $has_free = in_array($free, $active, true); $has_pro = in_array($pro, $active, true); if (!$has_free || !$has_pro) { return false; } $rest = array_values(array_diff($active, [$free, $pro])); $merged = array_merge([$free, $pro], $rest); if ($merged === array_values($active)) { return false; } update_option('active_plugins', $merged); return true; } /** * If Yatra Free 3.0+ is active and an old Yatra Pro (< 3.0.0) is active, deactivate Pro and queue an admin notice. */ function yatra_deactivate_incompatible_old_pro(): void { if (!defined('YATRA_VERSION')) { return; } if (version_compare(YATRA_VERSION, '3.0.0', '<')) { return; } if (!function_exists('get_plugin_data')) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } $pro_file = WP_PLUGIN_DIR . '/yatra-pro/yatra-pro.php'; if (!is_readable($pro_file)) { return; } $data = get_plugin_data($pro_file, false, false); $pro_version = isset($data['Version']) ? trim((string) $data['Version']) : '0'; if ($pro_version === '' || yatra_is_pro_version_compatible($pro_version)) { return; } if (!function_exists('is_plugin_active')) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } if (!is_plugin_active('yatra-pro/yatra-pro.php')) { return; } deactivate_plugins('yatra-pro/yatra-pro.php', true); set_transient( 'yatra_admin_notice_incompatible_pro_deactivated', [ 'pro_version' => $pro_version, 'min_required' => yatra_get_minimum_compatible_pro_version(), ], WEEK_IN_SECONDS ); } /** * Run guard once this file is loaded (yatra.php included after constants). */ function yatra_run_incompatible_pro_guard(): void { yatra_normalize_yatra_plugins_active_order(); yatra_deactivate_incompatible_old_pro(); } /** * Admin notice after we deactivated incompatible Pro. */ function yatra_admin_notice_incompatible_pro_deactivated(): void { if (!is_admin() || !current_user_can('activate_plugins')) { return; } $payload = get_transient('yatra_admin_notice_incompatible_pro_deactivated'); if (!is_array($payload)) { return; } $pro_v = isset($payload['pro_version']) ? sanitize_text_field((string) $payload['pro_version']) : ''; $min_v = isset($payload['min_required']) ? sanitize_text_field((string) $payload['min_required']) : yatra_get_minimum_compatible_pro_version(); $dismiss_url = wp_nonce_url( add_query_arg('yatra_dismiss_pro_notice', '1'), 'yatra_dismiss_pro_notice' ); ?>

Yatra Pro %1$s or newer from your MantraBrain store account: %2$s to use Pro features with this version of Yatra.', 'yatra') ), esc_html($min_v), sprintf( '%2$s', esc_url($account_url), esc_html($account_url) ) ); ?>

$plugin_data Headers from the plugin file. */ function yatra_plugin_row_old_pro_warning(string $plugin_file, array $plugin_data): void { if (!defined('YATRA_VERSION') || version_compare(YATRA_VERSION, '3.0.0', '<')) { return; } $v = isset($plugin_data['Version']) ? trim((string) $plugin_data['Version']) : '0'; if ($v === '' || yatra_is_pro_version_compatible($v)) { return; } $account_url = yatra_get_compatible_pro_account_url(); $msg = sprintf( /* translators: 1: minimum Yatra Pro version, 2: account URL */ esc_html__( 'This Yatra Pro version is not compatible with Yatra 3.0. Activating it will cause a fatal error. Install Yatra Pro %1$s or newer from your MantraBrain store account (%2$s) before activating.', 'yatra' ), esc_html(yatra_get_minimum_compatible_pro_version()), esc_html($account_url) ); printf( '

%s

', $msg ); } add_action('after_plugin_row_yatra-pro/yatra-pro.php', 'yatra_plugin_row_old_pro_warning', 10, 2);