| @@ -35,20 +35,26 @@ | ||
| 35 | 35 | // add_filter('wp_sitemaps_enabled', '__return_true'); |
| 36 | 36 | //delete_option( "metasync_options" ); |
| 37 | 37 | //delete_option( "metasync_options_instant_indexing" ); |
| 38 | 38 | |
| 39 | - // Clean up announce ping counter and cron | |
| 39 | + // Clean up announce ping counter | |
| 40 | 40 | delete_option('metasync_announce_attempt_count'); |
| 41 | - $timestamp = wp_next_scheduled('metasync_announce_cron'); | |
| 42 | - if ($timestamp) { | |
| 43 | - wp_unschedule_event($timestamp, 'metasync_announce_cron'); | |
| 41 | + | |
| 42 | + // Unschedule every MetaSync cron hook so no orphaned events remain after deactivation | |
| 43 | + foreach (Metasync_Activator::$cron_hooks as $hook) { | |
| 44 | + wp_unschedule_hook($hook); | |
| 44 | 45 | } |
| 45 | 46 | |
| 46 | - flush_rewrite_rules(); | |
| 47 | + // Soft flush only (no .htaccess rewrite). A hard flush calls | |
| 48 | + // save_mod_rewrite_rules(), which opens the site's root .htaccess with an | |
| 49 | + // exclusive flock(). On hosts whose cache/optimizer layer also holds that | |
| 50 | + // lock (e.g. SiteGround + SG Optimizer), the deactivation request blocks on | |
| 51 | + // the lock until max_execution_time and the host returns a 500 — so the | |
| 52 | + // plugin never deactivates. MetaSync registers its rewrite rules via | |
| 53 | + // add_rewrite_rule (stored in the `rewrite_rules` option, NOT in .htaccess), | |
| 54 | + // so a soft flush fully clears them without ever touching the file. | |
| 55 | + flush_rewrite_rules(false); | |
| 47 | 56 | |
| 48 | - // Unschedule DB cleanup cron so no orphaned events remain after deactivation | |
| 49 | - $timestamp = wp_next_scheduled('metasync_db_cleanup'); | |
| 50 | - if ($timestamp) { | |
| 51 | - wp_unschedule_event($timestamp, 'metasync_db_cleanup'); | |
| 52 | - } | |
| 57 | + // Reset one-time cleanup flag so it re-runs on next activation/update | |
| 58 | + delete_option('metasync_wp299_cron_cleanup_done'); | |
| 53 | 59 | } |
| 54 | 60 | } |