Changeset 3457834
- Timestamp:
- 02/10/2026 09:55:45 AM (7 weeks ago)
- Location:
- wp-before-after-image-slider
- Files:
-
- 2 edited
-
tags/2.1.2/includes/features/Admin/PluginSync.php (modified) (6 diffs)
-
trunk/includes/features/Admin/PluginSync.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-before-after-image-slider/tags/2.1.2/includes/features/Admin/PluginSync.php
r3457783 r3457834 160 160 // Only run for admin users. 161 161 if ( ! current_user_can( 'activate_plugins' ) ) { 162 return; 163 } 164 165 // Skip dependency check if sync is in progress to avoid race condition. 166 if ( get_transient( 'bais_plugin_sync_needed' ) || get_transient( 'bais_plugin_sync_in_progress' ) ) { 162 167 return; 163 168 } … … 302 307 */ 303 308 private function perform_sync( array $sync_data ): void { 309 // Set flag to indicate sync is in progress (prevents dependency check race condition). 310 set_transient( 'bais_plugin_sync_in_progress', true, 60 ); 311 304 312 $target_slug = $sync_data['target_slug']; 305 313 $target_type = $sync_data['target_type']; … … 318 326 319 327 // Get the source version (the version that was just updated). 320 $source_slug = 'free' === $target_type ? self::PRO_SLUG : self::FREE_SLUG;328 $source_slug = 'free' === $target_type ? $this->get_pro_plugin_slug() : $this->get_free_plugin_slug(); 321 329 $source_version = $this->get_plugin_version( $source_slug ); 322 330 … … 325 333 $this->update_plugin( $target_slug ); 326 334 } 335 336 // Ensure both plugins are active after sync. 337 $this->ensure_both_plugins_active(); 327 338 } catch ( \Exception $e ) { 328 339 // Log error but don't break the admin. 329 340 error_log( 'BAIS Plugin Sync Error: ' . $e->getMessage() ); // phpcs:ignore 341 } finally { 342 // Clear sync in progress flag. 343 delete_transient( 'bais_plugin_sync_in_progress' ); 344 } 345 } 346 347 /** 348 * Ensure both free and pro plugins are active after sync. 349 * 350 * @return void 351 */ 352 private function ensure_both_plugins_active(): void { 353 if ( ! function_exists( 'is_plugin_active' ) ) { 354 require_once ABSPATH . 'wp-admin/includes/plugin.php'; 355 } 356 357 $free_slug = $this->get_free_plugin_slug(); 358 $pro_slug = $this->get_pro_plugin_slug(); 359 360 // Activate free plugin if it's installed but not active. 361 if ( $this->is_plugin_installed( $free_slug ) && ! is_plugin_active( $free_slug ) ) { 362 activate_plugin( $free_slug, '', false, true ); 363 } 364 365 // Activate pro plugin if it's installed but not active. 366 if ( $this->is_plugin_installed( $pro_slug ) && ! is_plugin_active( $pro_slug ) ) { 367 activate_plugin( $pro_slug, '', false, true ); 330 368 } 331 369 } … … 344 382 } 345 383 384 // Include required WordPress functions. 385 if ( ! function_exists( 'is_plugin_active' ) ) { 386 require_once ABSPATH . 'wp-admin/includes/plugin.php'; 387 } 388 389 // Remember if plugin was active before update. 390 $was_active = is_plugin_active( $plugin_slug ); 391 346 392 try { 347 393 // Create upgrader instance. … … 354 400 error_log( 'BAIS Plugin Sync Update Error: ' . $result->get_error_message() ); // phpcs:ignore 355 401 return false; 402 } 403 404 // Reactivate plugin if it was active before update. 405 if ( $was_active ) { 406 activate_plugin( $plugin_slug, '', false, true ); 356 407 } 357 408 -
wp-before-after-image-slider/trunk/includes/features/Admin/PluginSync.php
r3457783 r3457834 160 160 // Only run for admin users. 161 161 if ( ! current_user_can( 'activate_plugins' ) ) { 162 return; 163 } 164 165 // Skip dependency check if sync is in progress to avoid race condition. 166 if ( get_transient( 'bais_plugin_sync_needed' ) || get_transient( 'bais_plugin_sync_in_progress' ) ) { 162 167 return; 163 168 } … … 302 307 */ 303 308 private function perform_sync( array $sync_data ): void { 309 // Set flag to indicate sync is in progress (prevents dependency check race condition). 310 set_transient( 'bais_plugin_sync_in_progress', true, 60 ); 311 304 312 $target_slug = $sync_data['target_slug']; 305 313 $target_type = $sync_data['target_type']; … … 318 326 319 327 // Get the source version (the version that was just updated). 320 $source_slug = 'free' === $target_type ? self::PRO_SLUG : self::FREE_SLUG;328 $source_slug = 'free' === $target_type ? $this->get_pro_plugin_slug() : $this->get_free_plugin_slug(); 321 329 $source_version = $this->get_plugin_version( $source_slug ); 322 330 … … 325 333 $this->update_plugin( $target_slug ); 326 334 } 335 336 // Ensure both plugins are active after sync. 337 $this->ensure_both_plugins_active(); 327 338 } catch ( \Exception $e ) { 328 339 // Log error but don't break the admin. 329 340 error_log( 'BAIS Plugin Sync Error: ' . $e->getMessage() ); // phpcs:ignore 341 } finally { 342 // Clear sync in progress flag. 343 delete_transient( 'bais_plugin_sync_in_progress' ); 344 } 345 } 346 347 /** 348 * Ensure both free and pro plugins are active after sync. 349 * 350 * @return void 351 */ 352 private function ensure_both_plugins_active(): void { 353 if ( ! function_exists( 'is_plugin_active' ) ) { 354 require_once ABSPATH . 'wp-admin/includes/plugin.php'; 355 } 356 357 $free_slug = $this->get_free_plugin_slug(); 358 $pro_slug = $this->get_pro_plugin_slug(); 359 360 // Activate free plugin if it's installed but not active. 361 if ( $this->is_plugin_installed( $free_slug ) && ! is_plugin_active( $free_slug ) ) { 362 activate_plugin( $free_slug, '', false, true ); 363 } 364 365 // Activate pro plugin if it's installed but not active. 366 if ( $this->is_plugin_installed( $pro_slug ) && ! is_plugin_active( $pro_slug ) ) { 367 activate_plugin( $pro_slug, '', false, true ); 330 368 } 331 369 } … … 344 382 } 345 383 384 // Include required WordPress functions. 385 if ( ! function_exists( 'is_plugin_active' ) ) { 386 require_once ABSPATH . 'wp-admin/includes/plugin.php'; 387 } 388 389 // Remember if plugin was active before update. 390 $was_active = is_plugin_active( $plugin_slug ); 391 346 392 try { 347 393 // Create upgrader instance. … … 354 400 error_log( 'BAIS Plugin Sync Update Error: ' . $result->get_error_message() ); // phpcs:ignore 355 401 return false; 402 } 403 404 // Reactivate plugin if it was active before update. 405 if ( $was_active ) { 406 activate_plugin( $plugin_slug, '', false, true ); 356 407 } 357 408
Note: See TracChangeset
for help on using the changeset viewer.