query( $wpdb->prepare( 'DROP TABLE IF EXISTS %i', $table ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.SchemaChange,WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching } }; /** * Clean up options / postmeta / termmeta for the currently active blog. * * @return void */ $airygen_cleanup_current_blog = static function () use ( $wpdb, $airygen_clear_tables, $airygen_clear_options, $airygen_clear_meta, $airygen_drop_tables_for_prefix ): void { // ── 1. Drop custom tables ───────────────────────────────────────────────── if ( $airygen_clear_tables ) { $airygen_drop_tables_for_prefix( $wpdb->prefix ); } // ── 2. Delete wp_options entries ────────────────────────────────────────── if ( $airygen_clear_options ) { // // phpcs:ignore WordPress.DB.DirectDatabaseQuery $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s", 'airygen\_%', 'airygen-seo%' ) ); } // ── 3. Delete postmeta / termmeta ───────────────────────────────────────── if ( $airygen_clear_meta ) { // // phpcs:ignore WordPress.DB.DirectDatabaseQuery $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->postmeta} WHERE meta_key LIKE %s", '\_airygen\_%' ) ); // // phpcs:ignore WordPress.DB.DirectDatabaseQuery $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->termmeta} WHERE meta_key LIKE %s", '\_airygen\_%' ) ); } }; if ( is_multisite() ) { // Iterate every blog in the network. $airygen_blog_ids = get_sites( array( 'fields' => 'ids', 'number' => 0, // no limit. ) ); // @phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited foreach ( $airygen_blog_ids as $blog_id ) { switch_to_blog( $blog_id ); $airygen_cleanup_current_blog(); restore_current_blog(); } // wp_usermeta is shared across the entire network – clean it once. if ( $airygen_clear_meta ) { // // phpcs:ignore WordPress.DB.DirectDatabaseQuery $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE %s", '\_airygen\_%' ) ); } // Remove the network-level preferences option itself. if ( $airygen_clear_options ) { delete_site_option( 'airygen_uninstall' ); } } else { // Single-site installation. $airygen_cleanup_current_blog(); if ( $airygen_clear_meta ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE %s", '\_airygen\_%' ) ); } }