esc_like('adghost_') . '%'; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- one-off lookup of this plugin's own option names by prefix; there is no API for it. $options = $wpdb->get_col($wpdb->prepare( "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE %s", $prefix )); foreach ($options as $option) { delete_option($option); } // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- one-off lookup of this plugin's own option names by prefix; there is no API for it. $transients = $wpdb->get_col($wpdb->prepare( "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE %s", $wpdb->esc_like('_transient_adghost_') . '%' )); foreach ($transients as $name) { delete_transient(substr($name, strlen('_transient_'))); } // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- removes this plugin's own transient rows on uninstall. $wpdb->query($wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s", $wpdb->esc_like('_transient_timeout_adghost_') . '%' )); delete_post_meta_by_key('_adghost_disable_ads'); delete_option('widget_adghost_ad'); $sidebars = get_option('sidebars_widgets'); if (is_array($sidebars)) { $changed = false; foreach ($sidebars as $sidebar => $widgets) { if (!is_array($widgets)) { continue; } $kept = array_values(array_filter($widgets, static function ($widget) { return strpos((string) $widget, 'adghost_ad-') !== 0; })); if (count($kept) !== count($widgets)) { $sidebars[$sidebar] = $kept; $changed = true; } } if ($changed) { update_option('sidebars_widgets', $sidebars); } } adghost_uninstall_runtime_files(); } function adghost_uninstall_runtime_files() { $generator = __DIR__ . '/includes/class-script-generator.php'; if (!file_exists($generator)) { return; } require_once $generator; if (method_exists('AdGhost_Script_Generator', 'delete_local_scripts')) { AdGhost_Script_Generator::delete_local_scripts(); } } if (is_multisite()) { foreach (get_sites(['fields' => 'ids', 'number' => 0]) as $blog_id) { switch_to_blog($blog_id); adghost_uninstall_site(); restore_current_blog(); } } else { adghost_uninstall_site(); }