PluginProbe
Yatra – Travel Booking & Tour Operator Software / 2.3.2
Yatra – Travel Booking & Tour Operator Software v2.3.2
3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 2.0.10 2.0.11 All 82 releases
yatra / core / ProCompatibility.php

ProCompatibility.php in Yatra – Travel Booking & Tour Operator Software 2.3.2, at core/ProCompatibility.php

845 lines 42.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Yatra Pro Compatibility Checker
4 *
5 * Checks for old individual plugins and shows notice to upgrade to Yatra Pro 2.0.0
6 *
7 * @package Yatra
8 * @since 2.0.0
9 */
10
11 if (!defined('ABSPATH')) {
12 exit;
13 }
14
15 class Yatra_Pro_Compatibility
16 {
17 /**
18 * List of old individual plugins that are now integrated into Yatra Pro 2.0.0
19 */
20 private $old_plugins = [
21 'yatra-downloads/yatra-downloads.php',
22 'yatra-2checkout/yatra-2checkout.php',
23 'yatra-authorizenet/yatra-authorizenet.php',
24 'yatra-availability-conditions/yatra-availability-conditions.php',
25 'yatra-google-calendar/yatra-google-calendar.php',
26 'yatra-partial-payment/yatra-partial-payment.php',
27 'yatra-razorpay/yatra-razorpay.php',
28 'yatra-review/yatra-review.php',
29 'yatra-services/yatra-services.php',
30 'yatra-square/yatra-square.php',
31 'yatra-stripe/yatra-stripe.php'
32 ];
33
34 /**
35 * Plugin names for display
36 */
37 private $plugin_names = [
38 'yatra-downloads/yatra-downloads.php' => 'Yatra Downloads',
39 'yatra-2checkout/yatra-2checkout.php' => 'Yatra 2Checkout',
40 'yatra-authorizenet/yatra-authorizenet.php' => 'Yatra AuthorizeNet',
41 'yatra-availability-conditions/yatra-availability-conditions.php' => 'Yatra Availability Conditions',
42 'yatra-google-calendar/yatra-google-calendar.php' => 'Yatra Google Calendar',
43 'yatra-partial-payment/yatra-partial-payment.php' => 'Yatra Partial Payment',
44 'yatra-razorpay/yatra-razorpay.php' => 'Yatra Razorpay',
45 'yatra-review/yatra-review.php' => 'Yatra Review',
46 'yatra-services/yatra-services.php' => 'Yatra Services',
47 'yatra-square/yatra-square.php' => 'Yatra Square',
48 'yatra-stripe/yatra-stripe.php' => 'Yatra Stripe'
49 ];
50
51 /**
52 * Mapping of old plugins to Yatra Pro features
53 */
54 private $plugin_to_feature_mapping = [
55 'yatra-downloads/yatra-downloads.php' => 'downloads',
56 'yatra-2checkout/yatra-2checkout.php' => 'payment_gateways',
57 'yatra-authorizenet/yatra-authorizenet.php' => 'payment_gateways',
58 'yatra-availability-conditions/yatra-availability-conditions.php' => 'availability_conditions',
59 'yatra-google-calendar/yatra-google-calendar.php' => 'google_calendar',
60 'yatra-partial-payment/yatra-partial-payment.php' => 'partial_payment',
61 'yatra-razorpay/yatra-razorpay.php' => 'payment_gateways',
62 'yatra-review/yatra-review.php' => 'review_ratings',
63 'yatra-services/yatra-services.php' => 'services',
64 'yatra-square/yatra-square.php' => 'payment_gateways',
65 'yatra-stripe/yatra-stripe.php' => 'payment_gateways'
66 ];
67
68 /**
69 * Constructor
70 */
71 public function __construct()
72 {
73 add_action('admin_init', array($this, 'check_compatibility'));
74 add_action('admin_notices', array($this, 'show_compatibility_notice'));
75 add_action('wp_ajax_yatra_enable_feature_and_deactivate', array($this, 'handle_enable_feature_and_deactivate'));
76 add_action('wp_ajax_yatra_go_to_features', array($this, 'handle_go_to_features'));
77 add_action('wp_ajax_yatra_activate_pro', array($this, 'handle_activate_pro'));
78 add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'));
79 }
80
81 /**
82 * Check if any old plugins are active
83 *
84 * @return array Array of active old plugins
85 */
86 public function get_active_old_plugins()
87 {
88 $active_plugins = get_option('active_plugins', array());
89 $active_old_plugins = array();
90
91 foreach ($this->old_plugins as $plugin) {
92 if (in_array($plugin, $active_plugins)) {
93 $active_old_plugins[] = $plugin;
94 }
95 }
96
97 return $active_old_plugins;
98 }
99
100 /**
101 * Check if all old plugins are deactivated
102 *
103 * @return bool True if all old plugins are deactivated
104 */
105 public function are_all_old_plugins_deactivated()
106 {
107 $active_old_plugins = $this->get_active_old_plugins();
108 return empty($active_old_plugins);
109 }
110
111 /**
112 * Get plugin display name
113 *
114 * @param string $plugin_file Plugin file path
115 * @return string Plugin display name
116 */
117 public function get_plugin_display_name($plugin_file)
118 {
119 return isset($this->plugin_names[$plugin_file]) ? $this->plugin_names[$plugin_file] : $plugin_file;
120 }
121
122 /**
123 * Check compatibility on admin init
124 */
125 public function check_compatibility()
126 {
127 // Only show notice if there are active old plugins
128 if (!$this->are_all_old_plugins_deactivated()) {
129 add_action('admin_notices', array($this, 'show_compatibility_notice'));
130 }
131 }
132
133 /**
134 * Show compatibility notice
135 */
136 public function show_compatibility_notice()
137 {
138 $active_old_plugins = $this->get_active_old_plugins();
139
140 if (empty($active_old_plugins)) {
141 return;
142 }
143
144 $plugin_names = array();
145 foreach ($active_old_plugins as $plugin) {
146 $plugin_names[] = $this->get_plugin_display_name($plugin);
147 }
148
149 $plugin_list = implode(', ', $plugin_names);
150 $plugin_count = count($active_old_plugins);
151 $yatra_pro_status = $this->get_yatra_pro_status();
152
153 // Different messages based on Yatra Pro status
154 if ($yatra_pro_status['needs_installation']) {
155 $message = sprintf(
156 _n(
157 'The following plugin has been integrated into Yatra Pro 2.0.0 and onwards: <strong>%s</strong>. To use these features, you need to install Yatra Pro 2.0.0. <em>Note: Updates for this plugin will only be available in Yatra Pro from now onwards.</em>',
158 'The following plugins have been integrated into Yatra Pro 2.0.0 and onwards: <strong>%s</strong>. To use these features, you need to install Yatra Pro 2.0.0. <em>Note: Updates for these plugins will only be available in Yatra Pro from now onwards.</em>',
159 $plugin_count,
160 'yatra'
161 ),
162 $plugin_list
163 );
164 } elseif ($yatra_pro_status['needs_activation']) {
165 $message = sprintf(
166 _n(
167 'The following plugin has been integrated into Yatra Pro 2.0.0 and onwards: <strong>%s</strong>. Please activate Yatra Pro 2.0.0 to use these features. <em>Note: Updates for this plugin will only be available in Yatra Pro from now onwards.</em>',
168 'The following plugins have been integrated into Yatra Pro 2.0.0 and onwards: <strong>%s</strong>. Please activate Yatra Pro 2.0.0 to use these features. <em>Note: Updates for these plugins will only be available in Yatra Pro from now onwards.</em>',
169 $plugin_count,
170 'yatra'
171 ),
172 $plugin_list
173 );
174 } elseif ($yatra_pro_status['needs_upgrade']) {
175 $message = sprintf(
176 _n(
177 'The following plugin has been integrated into Yatra Pro 2.0.0 and onwards: <strong>%s</strong>. Please upgrade Yatra Pro to version 2.0.0 or higher to use these features. <em>Note: Updates for this plugin will only be available in Yatra Pro from now onwards.</em>',
178 'The following plugins have been integrated into Yatra Pro 2.0.0 and onwards: <strong>%s</strong>. Please upgrade Yatra Pro to version 2.0.0 or higher to use these features. <em>Note: Updates for these plugins will only be available in Yatra Pro from now onwards.</em>',
179 $plugin_count,
180 'yatra'
181 ),
182 $plugin_list
183 );
184 } else {
185 $message = sprintf(
186 _n(
187 'The following plugin has been integrated into Yatra Pro 2.0.0 and onwards: <strong>%s</strong>. Please make sure you have updated Yatra Pro to version 2.0.0, enable the related features, and deactivate this plugin. <em>Note: Updates for this plugin will only be available in Yatra Pro from now onwards.</em>',
188 'The following plugins have been integrated into Yatra Pro 2.0.0 and onwards: <strong>%s</strong>. Please make sure you have updated Yatra Pro to version 2.0.0, enable the related features, and deactivate these plugins. <em>Note: Updates for these plugins will only be available in Yatra Pro from now onwards.</em>',
189 $plugin_count,
190 'yatra'
191 ),
192 $plugin_list
193 );
194 }
195
196 ?>
197 <div class="notice notice-warning is-dismissible yatra-pro-compatibility-notice" style="border-left: 4px solid #f0b849; background: linear-gradient(135deg, #fff8e1 0%, #fffbf0 100%); box-shadow: 0 2px 8px rgba(240, 184, 73, 0.15); margin: 20px 0; padding: 20px;">
198 <div style="display: flex; align-items: flex-start; gap: 15px;">
199 <div style="flex-shrink: 0; margin-top: 2px;">
200 <span class="dashicons dashicons-warning" style="font-size: 24px; color: #f0b849; text-shadow: 0 1px 2px rgba(240, 184, 73, 0.3);"></span>
201 </div>
202 <div style="flex: 1;">
203 <h3 style="margin: 0 0 12px 0; color: #8a6914; font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 8px;">
204 <span class="dashicons dashicons-update" style="color: #f0b849; animation: pulse 2s ease-in-out infinite;"></span>
205 <?php _e('Yatra Pro 2.0.0 Compatibility Update', 'yatra'); ?>
206 </h3>
207 <div style="background: rgba(255, 255, 255, 0.7); padding: 15px; border-radius: 8px; border: 1px solid rgba(240, 184, 73, 0.2); margin-bottom: 15px;">
208 <p style="margin: 0; color: #5d4e37; line-height: 1.6; font-size: 14px;">
209 <?php echo $message; ?>
210 </p>
211 </div>
212
213 <div style="display: flex; flex-wrap: wrap; gap: 10px; align-items: center;">
214 <?php if ($yatra_pro_status['is_compatible']): ?>
215 <button type="button" class="button button-primary yatra-enable-feature-btn" data-nonce="<?php echo wp_create_nonce('yatra_enable_feature'); ?>" style="background: linear-gradient(135deg, #0073aa 0%, #005a87 100%); border: none; border-radius: 6px; padding: 10px 16px; font-weight: 600; box-shadow: 0 2px 4px rgba(0, 115, 170, 0.3); transition: all 0.3s ease; display: inline-flex; align-items: center; gap: 6px;">
216 <span class="dashicons dashicons-yes-alt" style="font-size: 16px; line-height: 1;"></span>
217 <span><?php _e('Enable Feature & Deactivate', 'yatra'); ?></span>
218 </button>
219
220 <button type="button" class="button button-secondary yatra-go-to-features-btn" data-nonce="<?php echo wp_create_nonce('yatra_go_to_features'); ?>" style="background: linear-gradient(135deg, #f0f0f1 0%, #e8e8e9 100%); border: 1px solid #c3c4c7; border-radius: 6px; padding: 10px 16px; font-weight: 600; color: #50575e; transition: all 0.3s ease; display: inline-flex; align-items: center; gap: 6px;">
221 <span class="dashicons dashicons-admin-generic" style="font-size: 16px; line-height: 1;"></span>
222 <span><?php _e('Go to Features', 'yatra'); ?></span>
223 </button>
224 <?php elseif ($yatra_pro_status['needs_installation']): ?>
225 <a href="https://store.mantrabrain.com/account" target="_blank" class="button button-primary" style="background: linear-gradient(135deg, #0073aa 0%, #005a87 100%); border: none; border-radius: 6px; padding: 10px 16px; font-weight: 600; box-shadow: 0 2px 4px rgba(0, 115, 170, 0.3); transition: all 0.3s ease; text-decoration: none; display: inline-flex; align-items: center; gap: 6px;">
226 <span class="dashicons dashicons-download" style="font-size: 16px; line-height: 1;"></span>
227 <span><?php _e('Download Yatra Pro', 'yatra'); ?></span>
228 </a>
229
230 <a href="https://wpyatra.com/pricing/" target="_blank" class="button button-secondary" style="background: linear-gradient(135deg, #f0f0f1 0%, #e8e8e9 100%); border: 1px solid #c3c4c7; border-radius: 6px; padding: 10px 16px; font-weight: 600; color: #50575e; text-decoration: none; transition: all 0.3s ease; display: inline-flex; align-items: center; gap: 6px;">
231 <span class="dashicons dashicons-cart" style="font-size: 16px; line-height: 1;"></span>
232 <span><?php _e('Purchase License', 'yatra'); ?></span>
233 </a>
234 <?php elseif ($yatra_pro_status['needs_activation']): ?>
235 <button type="button" class="button button-primary yatra-activate-pro-btn" data-nonce="<?php echo wp_create_nonce('yatra_activate_pro'); ?>" style="background: linear-gradient(135deg, #0073aa 0%, #005a87 100%); border: none; border-radius: 6px; padding: 10px 16px; font-weight: 600; box-shadow: 0 2px 4px rgba(0, 115, 170, 0.3); transition: all 0.3s ease; display: inline-flex; align-items: center; gap: 6px;">
236 <span class="dashicons dashicons-yes" style="font-size: 16px; line-height: 1;"></span>
237 <span><?php echo esc_js(__('Activate Yatra Pro', 'yatra')); ?></span>
238 </button>
239 <?php elseif ($yatra_pro_status['needs_upgrade']): ?>
240 <a href="https://store.mantrabrain.com/account" target="_blank" class="button button-primary" style="background: linear-gradient(135deg, #0073aa 0%, #005a87 100%); border: none; border-radius: 6px; padding: 10px 16px; font-weight: 600; box-shadow: 0 2px 4px rgba(0, 115, 170, 0.3); transition: all 0.3s ease; text-decoration: none; display: inline-flex; align-items: center; gap: 6px;">
241 <span class="dashicons dashicons-admin-network" style="font-size: 16px; line-height: 1;"></span>
242 <span><?php _e('Manage License', 'yatra'); ?></span>
243 </a>
244
245 <a href="https://store.mantrabrain.com/account" target="_blank" class="button button-secondary" style="background: linear-gradient(135deg, #f0f0f1 0%, #e8e8e9 100%); border: 1px solid #c3c4c7; border-radius: 6px; padding: 10px 16px; font-weight: 600; color: #50575e; text-decoration: none; transition: all 0.3s ease; display: inline-flex; align-items: center; gap: 6px;">
246 <span class="dashicons dashicons-download" style="font-size: 16px; line-height: 1;"></span>
247 <span><?php _e('Download Latest', 'yatra'); ?></span>
248 </a>
249 <?php endif; ?>
250
251 <a href="<?php echo admin_url('plugins.php'); ?>" class="button button-secondary" style="background: linear-gradient(135deg, #f0f0f1 0%, #e8e8e9 100%); border: 1px solid #c3c4c7; border-radius: 6px; padding: 10px 16px; font-weight: 600; color: #50575e; text-decoration: none; transition: all 0.3s ease; display: inline-flex; align-items: center; gap: 6px;">
252 <span class="dashicons dashicons-admin-plugins" style="font-size: 16px; line-height: 1;"></span>
253 <span><?php _e('Go to Plugins Page', 'yatra'); ?></span>
254 </a>
255 </div>
256
257 <div style="margin-top: 15px; padding: 12px; background: rgba(240, 184, 73, 0.1); border-radius: 6px; border-left: 3px solid #f0b849;">
258 <p style="margin: 0; color: #8a6914; font-size: 13px; font-style: italic;">
259 <span class="dashicons dashicons-info" style="margin-right: 6px; color: #f0b849;"></span>
260 <?php
261 if ($yatra_pro_status['is_compatible']) {
262 _e('This will automatically deactivate the old plugins and enable the corresponding features in Yatra Pro 2.0.0. Future updates for these plugins will only be available in Yatra Pro.', 'yatra');
263 } elseif ($yatra_pro_status['needs_installation']) {
264 _e('Yatra Pro 2.0.0 is required to use these integrated features. Download Yatra Pro from your account at store.mantrabrain.com/account or purchase a license to unlock all premium functionality and receive future updates.', 'yatra');
265 } elseif ($yatra_pro_status['needs_activation']) {
266 _e('Yatra Pro is installed but not activated. Activate it to use the integrated features and receive future updates.', 'yatra');
267 } elseif ($yatra_pro_status['needs_upgrade']) {
268 _e('Your Yatra Pro version is outdated. Manage your license to upgrade to version 2.0.0 or higher, or download the latest version from your account to use these features and receive future updates.', 'yatra');
269 }
270 ?>
271 </p>
272 </div>
273
274 <?php if ($yatra_pro_status['needs_installation']): ?>
275 <div style="margin-top: 15px; padding: 15px; background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%); border-radius: 8px; border: 1px solid #dee2e6;">
276 <h4 style="margin: 0 0 10px 0; color: #495057; font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 8px;">
277 <span class="dashicons dashicons-admin-tools" style="color: #0073aa;"></span>
278 <?php _e('Installation Instructions:', 'yatra'); ?>
279 </h4>
280 <ol style="margin: 0; padding-left: 20px; color: #6c757d; font-size: 13px; line-height: 1.6;">
281 <li><?php _e('Click "Download Yatra Pro" to go to your account page', 'yatra'); ?></li>
282 <li><?php _e('Download the Yatra Pro plugin file from your account', 'yatra'); ?></li>
283 <li><?php _e('Go to WordPress Admin → Plugins → Add New → Upload Plugin', 'yatra'); ?></li>
284 <li><?php _e('Upload and activate the Yatra Pro plugin', 'yatra'); ?></li>
285 <li><?php _e('Return here and click "Enable Feature & Deactivate" to migrate your old plugins', 'yatra'); ?></li>
286 </ol>
287 </div>
288 <?php endif; ?>
289
290 <?php if ($yatra_pro_status['needs_upgrade']): ?>
291 <div style="margin-top: 15px; padding: 15px; background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%); border-radius: 8px; border: 1px solid #dee2e6;">
292 <h4 style="margin: 0 0 10px 0; color: #495057; font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 8px;">
293 <span class="dashicons dashicons-admin-network" style="color: #0073aa;"></span>
294 <?php _e('Upgrade Instructions:', 'yatra'); ?>
295 </h4>
296 <ol style="margin: 0; padding-left: 20px; color: #6c757d; font-size: 13px; line-height: 1.6;">
297 <li><?php _e('Click "Manage License" to access your license settings', 'yatra'); ?></li>
298 <li><?php _e('Check your license status and update if needed', 'yatra'); ?></li>
299 <li><?php _e('Click "Download Latest" to get the newest version from your account', 'yatra'); ?></li>
300 <li><?php _e('Upload and activate the updated Yatra Pro plugin', 'yatra'); ?></li>
301 <li><?php _e('Return here and click "Enable Feature & Deactivate" to migrate your old plugins', 'yatra'); ?></li>
302 </ol>
303 </div>
304 <?php endif; ?>
305 </div>
306 </div>
307
308 <div class="yatra-compatibility-status" style="display: none; margin-top: 15px; padding: 15px; background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%); border-radius: 8px; border: 1px solid #dee2e6;">
309 <p class="yatra-status-message" style="margin: 0; font-weight: 500; display: flex; align-items: center; gap: 8px;"></p>
310 </div>
311 </div>
312
313 <style>
314 @keyframes pulse {
315 0%, 100% { opacity: 1; transform: scale(1); }
316 50% { opacity: 0.7; transform: scale(1.05); }
317 }
318
319 .yatra-pro-compatibility-notice .button:hover {
320 transform: translateY(-1px);
321 box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
322 }
323
324 .yatra-pro-compatibility-notice .button-primary:hover {
325 background: linear-gradient(135deg, #005a87 0%, #004a70 100%) !important;
326 }
327
328 .yatra-pro-compatibility-notice .button-secondary:hover {
329 background: linear-gradient(135deg, #e8e8e9 0%, #dcdcde 100%) !important;
330 border-color: #8c8f94 !important;
331 }
332 </style>
333 <?php
334 }
335
336 /**
337 * Get list of all old plugins (for reference)
338 *
339 * @return array Array of all old plugin files
340 */
341 public function get_all_old_plugins()
342 {
343 return $this->old_plugins;
344 }
345
346 /**
347 * Get plugin names mapping (for reference)
348 *
349 * @return array Array of plugin file to display name mapping
350 */
351 public function get_plugin_names()
352 {
353 return $this->plugin_names;
354 }
355
356 /**
357 * Check if a specific plugin is active
358 *
359 * @param string $plugin_file Plugin file path
360 * @return bool True if plugin is active
361 */
362 public function is_plugin_active($plugin_file)
363 {
364 $active_plugins = get_option('active_plugins', array());
365 return in_array($plugin_file, $active_plugins);
366 }
367
368 /**
369 * Get compatibility status
370 *
371 * @return array Array with compatibility information
372 */
373 public function get_compatibility_status()
374 {
375 $active_old_plugins = $this->get_active_old_plugins();
376
377 return array(
378 'is_compatible' => $this->are_all_old_plugins_deactivated(),
379 'active_old_plugins' => $active_old_plugins,
380 'active_old_plugins_count' => count($active_old_plugins),
381 'all_old_plugins' => $this->old_plugins,
382 'plugin_names' => $this->plugin_names
383 );
384 }
385
386 /**
387 * Enqueue scripts and styles
388 */
389 public function enqueue_scripts()
390 {
391 if (!$this->are_all_old_plugins_deactivated()) {
392 $this->inline_scripts();
393 }
394 }
395
396 /**
397 * Output inline scripts
398 */
399 private function inline_scripts()
400 {
401 $processing_text = esc_js(__('Processing...', 'yatra'));
402 $deactivating_text = esc_js(__('Deactivating plugins and enabling features...', 'yatra'));
403 $enable_text = esc_js(__('Enable Feature & Deactivate', 'yatra'));
404 $error_text = esc_js(__('An error occurred. Please try again.', 'yatra'));
405 $activating_text = esc_js(__('Activating...', 'yatra'));
406 $activating_pro_text = esc_js(__('Activating Yatra Pro...', 'yatra'));
407 $activate_pro_text = esc_js(__('Activate Yatra Pro', 'yatra'));
408
409 ?>
410 <script type="text/javascript">
411 /* Yatra Pro Compatibility Script */
412 (function() {
413 'use strict';
414
415 function initYatraCompatibility() {
416 if (typeof jQuery === 'undefined') {
417 setTimeout(initYatraCompatibility, 100);
418 return;
419 }
420
421 jQuery(document).ready(function($) {
422 // Handle Enable Feature & Deactivate button
423 $('.yatra-enable-feature-btn').on('click', function(e) {
424 e.preventDefault();
425
426 var $btn = $(this);
427 var $status = $('.yatra-compatibility-status');
428 var $message = $('.yatra-status-message');
429 var nonce = $btn.data('nonce');
430
431 // Disable button and show loading
432 $btn.prop('disabled', true);
433 $btn.find('.dashicons').removeClass('dashicons-yes-alt').addClass('dashicons-update').css('animation', 'spin 1s linear infinite');
434 $btn.find('span:not(.dashicons)').text('<?php echo $processing_text; ?>');
435
436 // Show status area
437 $status.show();
438 $message.html('<span class="dashicons dashicons-update" style="animation: spin 1s linear infinite;"></span> <?php echo $deactivating_text; ?>');
439
440 $.ajax({
441 url: ajaxurl,
442 type: 'POST',
443 data: {
444 action: 'yatra_enable_feature_and_deactivate',
445 nonce: nonce
446 },
447 success: function(response) {
448 if (response.success) {
449 $message.html('<span class="dashicons dashicons-yes" style="color: #46b450;"></span> ' + response.data.message);
450
451 // Reload page after 2 seconds
452 setTimeout(function() {
453 window.location.reload();
454 }, 2000);
455 } else {
456 $message.html('<span class="dashicons dashicons-warning" style="color: #dc3232;"></span> ' + response.data.message);
457 $btn.prop('disabled', false);
458 $btn.find('.dashicons').removeClass('dashicons-update').addClass('dashicons-yes-alt').css('animation', '');
459 $btn.find('span:not(.dashicons)').text('<?php echo $enable_text; ?>');
460 }
461 },
462 error: function() {
463 $message.html('<span class="dashicons dashicons-warning" style="color: #dc3232;"></span> <?php echo $error_text; ?>');
464 $btn.prop('disabled', false);
465 $btn.find('.dashicons').removeClass('dashicons-update').addClass('dashicons-yes-alt').css('animation', '');
466 $btn.find('span:not(.dashicons)').text('<?php echo $enable_text; ?>');
467 }
468 });
469 });
470
471 // Handle Go to Features button
472 $('.yatra-go-to-features-btn').on('click', function(e) {
473 e.preventDefault();
474
475 var $btn = $(this);
476 var nonce = $btn.data('nonce');
477
478 // Disable button and show loading
479 $btn.prop('disabled', true);
480 $btn.find('.dashicons').removeClass('dashicons-admin-generic').addClass('dashicons-update').css('animation', 'spin 1s linear infinite');
481
482 $.ajax({
483 url: ajaxurl,
484 type: 'POST',
485 data: {
486 action: 'yatra_go_to_features',
487 nonce: nonce
488 },
489 success: function(response) {
490 if (response.success) {
491 window.location.href = response.data.redirect_url;
492 } else {
493 alert(response.data.message);
494 $btn.prop('disabled', false);
495 $btn.find('.dashicons').removeClass('dashicons-update').addClass('dashicons-admin-generic').css('animation', '');
496 }
497 },
498 error: function() {
499 alert('<?php echo $error_text; ?>');
500 $btn.prop('disabled', false);
501 $btn.find('.dashicons').removeClass('dashicons-update').addClass('dashicons-admin-generic').css('animation', '');
502 }
503 });
504 });
505
506 // Handle Activate Yatra Pro button
507 $('.yatra-activate-pro-btn').on('click', function(e) {
508 e.preventDefault();
509
510 var $btn = $(this);
511 var $status = $('.yatra-compatibility-status');
512 var $message = $('.yatra-status-message');
513 var nonce = $btn.data('nonce');
514
515 // Disable button and show loading
516 $btn.prop('disabled', true);
517 $btn.find('.dashicons').removeClass('dashicons-yes').addClass('dashicons-update').css('animation', 'spin 1s linear infinite');
518 $btn.find('span:not(.dashicons)').text('<?php echo $activating_text; ?>');
519
520 // Show status area
521 $status.show();
522 $message.html('<span class="dashicons dashicons-update" style="animation: spin 1s linear infinite;"></span> <?php echo $activating_pro_text; ?>');
523
524 $.ajax({
525 url: ajaxurl,
526 type: 'POST',
527 data: {
528 action: 'yatra_activate_pro',
529 nonce: nonce
530 },
531 success: function(response) {
532 if (response.success) {
533 $message.html('<span class="dashicons dashicons-yes" style="color: #46b450;"></span> ' + response.data.message);
534
535 // Reload page after 2 seconds
536 setTimeout(function() {
537 window.location.reload();
538 }, 2000);
539 } else {
540 $message.html('<span class="dashicons dashicons-warning" style="color: #dc3232;"></span> ' + response.data.message);
541 $btn.prop('disabled', false);
542 $btn.find('.dashicons').removeClass('dashicons-update').addClass('dashicons-yes').css('animation', '');
543 $btn.find('span:not(.dashicons)').text('<?php echo $activate_pro_text; ?>');
544 }
545 },
546 error: function() {
547 $message.html('<span class="dashicons dashicons-warning" style="color: #dc3232;"></span> <?php echo $error_text; ?>');
548 $btn.prop('disabled', false);
549 $btn.find('.dashicons').removeClass('dashicons-update').addClass('dashicons-yes').css('animation', '');
550 $btn.find('span:not(.dashicons)').text('<?php echo $activate_pro_text; ?>');
551 }
552 });
553 });
554
555 // CSS for spin animation
556 var style = document.createElement('style');
557 style.textContent = '@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }';
558 document.head.appendChild(style);
559 });
560 }
561
562 // Initialize when DOM is ready
563 document.addEventListener('DOMContentLoaded', initYatraCompatibility);
564
565 // Also try to initialize immediately in case DOM is already ready
566 if (document.readyState !== 'loading') {
567 initYatraCompatibility();
568 }
569 })();
570 </script>
571 <?php
572 }
573
574 /**
575 * Handle Enable Feature & Deactivate AJAX request
576 */
577 public function handle_enable_feature_and_deactivate()
578 {
579 // Verify nonce
580 if (!wp_verify_nonce($_POST['nonce'], 'yatra_enable_feature')) {
581 wp_die('Security check failed');
582 }
583
584 // Check if user has permission
585 if (!current_user_can('activate_plugins')) {
586 wp_send_json_error(array('message' => __('You do not have permission to perform this action.', 'yatra')));
587 }
588
589 $active_old_plugins = $this->get_active_old_plugins();
590
591 if (empty($active_old_plugins)) {
592 wp_send_json_error(array('message' => __('No old plugins found to deactivate.', 'yatra')));
593 }
594
595 // Check Yatra Pro status
596 $yatra_pro_status = $this->get_yatra_pro_status();
597
598 if ($yatra_pro_status['needs_installation']) {
599 wp_send_json_error(array('message' => __('Yatra Pro is not installed. Please install and activate Yatra Pro 2.0.0 first.', 'yatra')));
600 }
601
602 if ($yatra_pro_status['needs_activation']) {
603 wp_send_json_error(array('message' => __('Yatra Pro is not activated. Please activate Yatra Pro 2.0.0 first.', 'yatra')));
604 }
605
606 if ($yatra_pro_status['needs_upgrade']) {
607 wp_send_json_error(array('message' => __('Please upgrade Yatra Pro to version 2.0.0 or higher to use this feature.', 'yatra')));
608 }
609
610 if (!$yatra_pro_status['is_compatible']) {
611 wp_send_json_error(array('message' => __('Yatra Pro 2.0.0 is required but not properly configured.', 'yatra')));
612 }
613
614 $deactivated_plugins = array();
615 $enabled_features = array();
616
617 // Deactivate old plugins
618 foreach ($active_old_plugins as $plugin) {
619 if (is_plugin_active($plugin)) {
620 deactivate_plugins($plugin);
621 $deactivated_plugins[] = $this->get_plugin_display_name($plugin);
622 }
623 }
624
625 // Enable corresponding features in Yatra Pro
626 foreach ($active_old_plugins as $plugin) {
627 if (isset($this->plugin_to_feature_mapping[$plugin])) {
628 $feature = $this->plugin_to_feature_mapping[$plugin];
629 $this->enable_yatra_pro_feature($feature);
630 $enabled_features[] = $feature;
631 }
632 }
633
634 $message = sprintf(
635 __('Successfully deactivated %d plugin(s) and enabled corresponding features in Yatra Pro 2.0.0. The page will reload shortly.', 'yatra'),
636 count($deactivated_plugins)
637 );
638
639 wp_send_json_success(array('message' => $message));
640 }
641
642 /**
643 * Handle Go to Features AJAX request
644 */
645 public function handle_go_to_features()
646 {
647 // Verify nonce
648 if (!wp_verify_nonce($_POST['nonce'], 'yatra_go_to_features')) {
649 wp_die('Security check failed');
650 }
651
652 // Check Yatra Pro status
653 $yatra_pro_status = $this->get_yatra_pro_status();
654
655 if ($yatra_pro_status['needs_installation']) {
656 wp_send_json_error(array('message' => __('Yatra Pro is not installed. Please install and activate Yatra Pro 2.0.0 first.', 'yatra')));
657 }
658
659 if ($yatra_pro_status['needs_activation']) {
660 wp_send_json_error(array('message' => __('Yatra Pro is not activated. Please activate Yatra Pro 2.0.0 first.', 'yatra')));
661 }
662
663 if ($yatra_pro_status['needs_upgrade']) {
664 wp_send_json_error(array('message' => __('Please upgrade Yatra Pro to version 2.0.0 or higher to access the features page.', 'yatra')));
665 }
666
667 if (!$yatra_pro_status['is_compatible']) {
668 wp_send_json_error(array('message' => __('Yatra Pro 2.0.0 is required but not properly configured.', 'yatra')));
669 }
670
671 // Redirect to Yatra Pro features page
672 $redirect_url = admin_url('admin.php?page=yatra-pro-features');
673
674 wp_send_json_success(array('redirect_url' => $redirect_url));
675 }
676
677 /**
678 * Handle Activate Yatra Pro AJAX request
679 */
680 public function handle_activate_pro()
681 {
682 // Verify nonce
683 if (!wp_verify_nonce($_POST['nonce'], 'yatra_activate_pro')) {
684 wp_die('Security check failed');
685 }
686
687 // Check if user has permission
688 if (!current_user_can('activate_plugins')) {
689 wp_send_json_error(array('message' => __('You do not have permission to perform this action.', 'yatra')));
690 }
691
692 // Check if Yatra Pro is installed
693 if (!$this->is_yatra_pro_installed()) {
694 wp_send_json_error(array('message' => __('Yatra Pro is not installed. Please install Yatra Pro first.', 'yatra')));
695 }
696
697 // Check if Yatra Pro is already activated
698 if ($this->is_yatra_pro_activated()) {
699 wp_send_json_error(array('message' => __('Yatra Pro is already activated.', 'yatra')));
700 }
701
702 // Activate Yatra Pro
703 $plugin_file = 'yatra-pro/yatra-pro.php';
704 $result = activate_plugin($plugin_file);
705
706 if (is_wp_error($result)) {
707 wp_send_json_error(array('message' => sprintf(__('Failed to activate Yatra Pro: %s', 'yatra'), $result->get_error_message())));
708 }
709
710 // Check if activation was successful
711 if (!is_plugin_active($plugin_file)) {
712 wp_send_json_error(array('message' => __('Yatra Pro activation failed. Please try again.', 'yatra')));
713 }
714
715 $message = __('Yatra Pro has been successfully activated! The page will reload shortly.', 'yatra');
716 wp_send_json_success(array('message' => $message));
717 }
718
719 /**
720 * Get Yatra Pro version
721 *
722 * @return string|false Yatra Pro version or false if not found
723 */
724 private function get_yatra_pro_version()
725 {
726 if (!function_exists('get_plugin_data')) {
727 require_once ABSPATH . 'wp-admin/includes/plugin.php';
728 }
729
730 $plugin_file = 'yatra-pro/yatra-pro.php';
731
732 if (is_plugin_active($plugin_file)) {
733 $plugin_data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin_file);
734 return isset($plugin_data['Version']) ? $plugin_data['Version'] : false;
735 }
736
737 return false;
738 }
739
740 /**
741 * Check if Yatra Pro is installed
742 *
743 * @return bool True if Yatra Pro is installed
744 */
745 private function is_yatra_pro_installed()
746 {
747 if (!function_exists('get_plugins')) {
748 require_once ABSPATH . 'wp-admin/includes/plugin.php';
749 }
750
751 $plugins = get_plugins();
752 return isset($plugins['yatra-pro/yatra-pro.php']);
753 }
754
755 /**
756 * Check if Yatra Pro is activated
757 *
758 * @return bool True if Yatra Pro is activated
759 */
760 private function is_yatra_pro_activated()
761 {
762 return is_plugin_active('yatra-pro/yatra-pro.php');
763 }
764
765 /**
766 * Get Yatra Pro installation status
767 *
768 * @return array Array with installation status information
769 */
770 private function get_yatra_pro_status()
771 {
772 $is_installed = $this->is_yatra_pro_installed();
773 $is_activated = $this->is_yatra_pro_activated();
774 $version = $this->get_yatra_pro_version();
775
776 return array(
777 'is_installed' => $is_installed,
778 'is_activated' => $is_activated,
779 'version' => $version,
780 'is_compatible' => $is_activated && $version && version_compare($version, '2.0.0', '>='),
781 'needs_installation' => !$is_installed,
782 'needs_activation' => $is_installed && !$is_activated,
783 'needs_upgrade' => $is_activated && $version && version_compare($version, '2.0.0', '<')
784 );
785 }
786
787 /**
788 * Enable Yatra Pro feature
789 *
790 * @param string $feature Feature name to enable
791 * @return bool True if feature was enabled successfully
792 */
793 private function enable_yatra_pro_feature($feature)
794 {
795 // Get current enabled features
796 $enabled_features = get_option('yatra_pro_enabled_features', array());
797
798 // Add the feature if not already enabled
799 if (!in_array($feature, $enabled_features)) {
800 $enabled_features[] = $feature;
801 update_option('yatra_pro_enabled_features', $enabled_features);
802 }
803
804 // Also enable specific feature settings if needed
805 switch ($feature) {
806 case 'downloads':
807 update_option('yatra_pro_downloads_enabled', 'yes');
808 break;
809 case 'payment_gateways':
810 update_option('yatra_pro_payment_gateways_enabled', 'yes');
811 break;
812 case 'availability_conditions':
813 update_option('yatra_pro_availability_conditions_enabled', 'yes');
814 break;
815 case 'google_calendar':
816 update_option('yatra_pro_google_calendar_enabled', 'yes');
817 break;
818 case 'partial_payment':
819 update_option('yatra_pro_partial_payment_enabled', 'yes');
820 break;
821 case 'review_ratings':
822 update_option('yatra_pro_review_ratings_enabled', 'yes');
823 break;
824 case 'services':
825 update_option('yatra_pro_services_enabled', 'yes');
826 break;
827 }
828
829 return true;
830 }
831
832 /**
833 * Get plugin to feature mapping
834 *
835 * @return array Array of plugin to feature mapping
836 */
837 public function get_plugin_to_feature_mapping()
838 {
839 return $this->plugin_to_feature_mapping;
840 }
841 }
842
843 // Initialize the compatibility checker
844 new Yatra_Pro_Compatibility();
845