query('SET FOREIGN_KEY_CHECKS = 0'); foreach (yatra_uninstall_free_table_suffixes() as $suffix) { $table = $wpdb->prefix . $suffix; // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $wpdb->query("DROP TABLE IF EXISTS `{$table}`"); } $wpdb->query('SET FOREIGN_KEY_CHECKS = 1'); // Scheduled work must go too, or WordPress keeps firing hooks for a plugin // that is no longer installed. $protectPro = yatra_uninstall_pro_still_installed(); $proHooks = yatra_uninstall_pro_owned_cron_hooks(); foreach ((array) _get_cron_array() as $timestamp => $hooks) { foreach ((array) $hooks as $hook => $events) { $hook = (string) $hook; if (strpos($hook, 'yatra') !== 0) { continue; } if ($protectPro && (strpos($hook, 'yatra_pro') === 0 || in_array($hook, $proHooks, true))) { continue; } foreach ((array) $events as $event) { wp_unschedule_event($timestamp, $hook, $event['args'] ?? []); } } } // Options and transients. `yatra_pro_` is left alone: those belong to Yatra // Pro, which removes them from its own uninstall.php, and deleting them // here would wipe Pro's settings whenever the free plugin is removed first. $options = $wpdb->get_col( "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE 'yatra\\_%' AND option_name NOT LIKE 'yatra\\_pro\\_%'" ); $proOptions = $protectPro ? yatra_uninstall_pro_owned_options() : []; foreach ((array) $options as $option) { if ($proOptions && in_array($option, $proOptions, true)) { continue; } delete_option($option); } $transients = $wpdb->get_col( "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '\\_transient\\_yatra\\_%' OR option_name LIKE '\\_transient\\_timeout\\_yatra\\_%'" ); foreach ((array) $transients as $transient) { delete_option($transient); } // User meta Yatra set on customers and staff. $wpdb->query("DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE 'yatra\\_%'"); } // Network-wide installs keep a separate set of tables and options per site, so // each one has to be cleaned on its own. if (is_multisite()) { $sites = get_sites(['fields' => 'ids', 'number' => 0]); foreach ((array) $sites as $siteId) { switch_to_blog((int) $siteId); yatra_uninstall_cleanup_site(); restore_current_blog(); } } else { yatra_uninstall_cleanup_site(); }