keep_data() ) { return false; } $registry = new Registry( $settings ); $registry->instantiate(); // Mark everything off first, so no delete re-creates what it just removed (e.g. the log table). foreach ( $settings->enabled_ids() as $id ) { $settings->set_enabled( $id, false ); } // Options that belong to a `record` item (store data that stays, like Test data's signing key) // are never swept below. A record item names its option in `option`; most have none. $keep = array(); foreach ( $registry->all() as $module ) { foreach ( (array) $module->data() as $item ) { if ( is_array( $item ) && 'record' === ( $item['kind'] ?? '' ) && isset( $item['option'] ) && is_string( $item['option'] ) && '' !== $item['option'] ) { $keep[ $item['option'] ] = true; } } foreach ( $module->data_items() as $item ) { Cleanup::purge( $item ); } } // Plugin-wide leftovers: every option and transient we own starts with `apwc_` (state, module // settings, caches, and anything a delete above re-created because its power-up was on). $names = $wpdb->get_col( // phpcs:ignore WordPress.DB.DirectDatabaseQuery $wpdb->prepare( "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s", $wpdb->esc_like( 'apwc_' ) . '%', $wpdb->esc_like( '_transient_apwc_' ) . '%', $wpdb->esc_like( '_transient_timeout_apwc_' ) . '%' ) ); foreach ( $names as $name ) { if ( ! isset( $keep[ $name ] ) ) { delete_option( $name ); } } if ( function_exists( 'as_unschedule_all_actions' ) ) { as_unschedule_all_actions( '', array(), Jobs::GROUP ); // Jobs still waiting to run. } return true; } $apwc_kept = false; if ( is_multisite() ) { foreach ( get_sites( array( 'fields' => 'ids', 'number' => 0, ) ) as $apwc_site_id ) { switch_to_blog( $apwc_site_id ); $apwc_kept = ! apwc_uninstall_site() || $apwc_kept; restore_current_blog(); } } else { $apwc_kept = ! apwc_uninstall_site(); } // User meta is shared by the whole network: only remove the panel theme choice if no site kept its data. if ( ! $apwc_kept ) { delete_metadata( 'user', 0, 'apwc_theme', '', true ); }