) goes when it holds no backup: only the // protection files, job.json and the records of finished jobs. With a backup in it, it stays. The // same for folders of ours left behind by an earlier random name. The plugin's classes are not // loaded here, so the test is written out. $rollbakr_own_only = static function ( $dir ) { $entries = @scandir( $dir ); // phpcs:ignore WordPress.PHP.NoSilencedErrors if ( ! is_array( $entries ) ) { return false; } foreach ( $entries as $name ) { if ( '.' === $name || '..' === $name ) { continue; } $path = $dir . '/' . $name; if ( is_link( $path ) ) { return false; } if ( is_dir( $path ) ) { if ( 'rollbakr-pro.lock' === $name || preg_match( '/^\d{4}-\d{2}-\d{2}-\d{6}-[a-z0-9]{6}\.(done|failed|cancelled|restore|deleted)$/', $name ) ) { continue; } return false; } if ( ! in_array( $name, array( '.htaccess', 'index.php', 'web.config', 'job.json' ), true ) ) { return false; } } return true; }; $rollbakr_wipe = static function ( $dir ) use ( &$rollbakr_wipe ) { foreach ( (array) ( @scandir( $dir ) ?: array() ) as $name ) { // phpcs:ignore WordPress.PHP.NoSilencedErrors if ( '.' === $name || '..' === $name ) { continue; } $path = $dir . '/' . $name; if ( is_dir( $path ) && ! is_link( $path ) ) { $rollbakr_wipe( $path ); } else { wp_delete_file( $path ); } } @rmdir( $dir ); // phpcs:ignore WordPress.PHP.NoSilencedErrors, WordPress.WP.AlternativeFunctions }; foreach ( glob( wp_normalize_path( WP_CONTENT_DIR ) . '/rollbakr-*', GLOB_ONLYDIR ) ?: array() as $rollbakr_dir ) { if ( preg_match( '/^rollbakr-[a-z0-9]{12}$/', basename( $rollbakr_dir ) ) && ! is_link( $rollbakr_dir ) && $rollbakr_own_only( $rollbakr_dir ) ) { $rollbakr_wipe( $rollbakr_dir ); } } foreach ( array( 'rollbakr_settings', 'rollbakr_storage_check', 'rollbakr_version' ) as $rollbakr_option ) { delete_option( $rollbakr_option ); } delete_transient( 'rollbakr_sizes' ); delete_transient( 'rollbakr_tidied' ); // Who closed the lines about ROLLBAKR Pro (the card on the Backups screen, the notice about an uploaded Pro). delete_metadata( 'user', 0, 'rollbakr_pro_card_hidden', '', true ); delete_metadata( 'user', 0, 'rollbakr_pro_ready_hidden', '', true );