get_col( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $qlmig_prefix ) . '%' ) ); foreach ( $qlmig_tables as $qlmig_table ) { $wpdb->query( $wpdb->prepare( 'DROP TABLE IF EXISTS %i', (string) $qlmig_table ) ); } } $qlmig_uploads = wp_upload_dir( null, false ); $qlmig_base = trailingslashit( wp_normalize_path( $qlmig_uploads['basedir'] ) ) . 'quick-launch-migrate'; /** * Deletes a directory tree, refusing anything outside the storage folder. * * @param string $dir Directory. * @param string $base Storage root. */ function qlmig_uninstall_rmdir( string $dir, string $base ): void { $real = realpath( $dir ); $root = realpath( $base ); if ( false === $real || false === $root || ! str_starts_with( $real . '/', $root . '/' ) ) { return; } $items = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $real, FilesystemIterator::SKIP_DOTS ), RecursiveIteratorIterator::CHILD_FIRST ); foreach ( $items as $item ) { if ( $item->isDir() && ! $item->isLink() ) { @rmdir( $item->getPathname() ); // phpcs:ignore } else { @unlink( $item->getPathname() ); // phpcs:ignore } } @rmdir( $real ); // phpcs:ignore } if ( is_dir( $qlmig_base ) ) { // Working folders sit in the private-{random} folder since 1.3.2, directly in the root before. foreach ( array_merge( array( $qlmig_base ), (array) glob( $qlmig_base . '/private-*', GLOB_ONLYDIR ) ) as $qlmig_dir ) { qlmig_uninstall_rmdir( $qlmig_dir . '/jobs', $qlmig_base ); qlmig_uninstall_rmdir( $qlmig_dir . '/incoming', $qlmig_base ); } if ( defined( 'QLMIG_UNINSTALL_DELETE_BACKUPS' ) && QLMIG_UNINSTALL_DELETE_BACKUPS ) { qlmig_uninstall_rmdir( $qlmig_base, $qlmig_base ); } } // Temporary direct-download links. Removing a link never deletes the backup // it points to (hard link: another name for the same file; symlink: a pointer). $qlmig_links = trailingslashit( wp_normalize_path( $qlmig_uploads['basedir'] ) ) . 'quick-launch-migrate-dl'; if ( is_dir( $qlmig_links ) ) { qlmig_uninstall_rmdir( $qlmig_links, $qlmig_links ); } // Backup summaries for the Backups table (the archives themselves are handled above). delete_option( 'qlmig_backup_index' );