query( 'DROP TABLE IF EXISTS `' . $wpdb->prefix . $t . '`' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared } } /** Deletes the dynamically named transients (and their timeouts) straight from the options table. @param object $wpdb wpdb-like (options, esc_like, prepare, query). */ public static function delete_dynamic_transients( object $wpdb ): void { foreach ( self::transient_prefixes() as $prefix ) { foreach ( array( '_transient_', '_transient_timeout_' ) as $kind ) { $like = $wpdb->esc_like( $kind . $prefix ) . '%'; $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s", $like ) ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared } } } /** Uninstall for the current site (call inside switch_to_blog on multisite). */ public static function run_site( object $wpdb ): void { $delete = self::wants_data_deleted( get_option( 'sg_settings', array() ) ); wp_clear_scheduled_hook( self::CRON_HOOK ); self::delete_dynamic_transients( $wpdb ); if ( $delete ) { self::drop_tables( $wpdb ); foreach ( self::options() as $o ) { delete_option( $o ); } } } /** Entry point for uninstall.php. */ public static function run(): void { global $wpdb; if ( function_exists( 'is_multisite' ) && is_multisite() ) { foreach ( get_sites( array( 'fields' => 'ids', 'number' => 0 ) ) as $id ) { switch_to_blog( (int) $id ); self::run_site( $wpdb ); restore_current_blog(); } } else { self::run_site( $wpdb ); } foreach ( self::site_transients() as $t ) { delete_site_transient( $t ); } } }