/ with .htaccess, web.config and index.php. "Keep on the server" * needs a folder outside the web root, where no browser can reach it whatever the server is * (Apache, nginx …); check() makes sure the folder is outside and writable. Nothing is fetched * through the site's URL: ROLLBAKR makes no HTTP request at all. * * @package ROLLBAKR */ defined( 'ABSPATH' ) || exit; /** * Create, protect and inspect the backup folder. */ class Rollbakr_Storage { /** Option: random part of the default folder name. */ const SUB = 'rollbakr_dir_sub'; /** Option: this site's identifier, written into every backup's manifest. */ const SITE = 'rollbakr_site_id'; /** Option: last result of check(). */ const CHECK = 'rollbakr_storage_check'; /** Start of the names of the files used by check(): rollbakr-check-.tar.gz and .sql.gz. */ const PROBE = 'rollbakr-check-'; /** @var string|null The folder a job step works in, fixed for the rest of the request (see pin()). */ private static $pinned = null; /** * Fix the backup folder for the rest of the request, or let it follow the settings again (null). * A restore replaces the options while it runs: its job file, lock and log must not move with them. * * @param string|null $dir Folder, or null. * @return void */ public static function pin( $dir ) { self::$pinned = null === $dir ? null : self::normalize( $dir ) . '/'; } /** * A path with '.' and '..' segments resolved, forward slashes, no trailing slash. * Does not touch the file system (realpath() needs the path to exist). * * @param string $path Path. * @return string */ public static function normalize( $path ) { $path = wp_normalize_path( (string) $path ); $root = str_starts_with( $path, '/' ) ? '/' : ( preg_match( '#^[A-Za-z]:/#', $path ) ? substr( $path, 0, 3 ) : '' ); $parts = array(); foreach ( explode( '/', substr( $path, strlen( $root ) ) ) as $part ) { if ( '' === $part || '.' === $part ) { continue; } if ( '..' === $part ) { array_pop( $parts ); continue; } $parts[] = $part; } return rtrim( $root . implode( '/', $parts ), '/' ); } /** * A path with symbolic links resolved: realpath() of the nearest existing ancestor, plus the * rest. So a link that leads into the install is seen for what it is. * * @param string $path Path. * @return string Normalized (see normalize()). */ public static function real( $path ) { $path = self::normalize( $path ); $rest = array(); $base = $path; while ( '' !== $base && ! file_exists( $base ) ) { $rest[] = basename( $base ); $parent = dirname( $base ); if ( $parent === $base ) { break; } $base = $parent; } $real = '' !== $base && file_exists( $base ) ? realpath( $base ) : false; if ( false === $real ) { return $path; } return self::normalize( rtrim( $real, '/' ) . ( $rest ? '/' . implode( '/', array_reverse( $rest ) ) : '' ) ); } /** * Whether a folder may be used as the backup folder: absolute, not the install or one of its * main folders (the deny-all .htaccess written there would take the site down), and not above them. * * @param string $dir Folder. * @return bool */ public static function is_allowed_dir( $dir ) { $dir = self::normalize( $dir ); if ( '' === $dir || ! path_is_absolute( $dir ) || '/' === $dir ) { return false; } $uploads = wp_get_upload_dir(); $protected = array( ABSPATH, WP_CONTENT_DIR, WP_PLUGIN_DIR, get_theme_root(), $uploads['basedir'], ABSPATH . 'wp-admin', ABSPATH . WPINC, ); $real = self::real( $dir ); foreach ( $protected as $p ) { $p = self::real( $p ); // Equal to a WordPress folder, or an ancestor of one (as written, or once links are resolved). if ( $dir === $p || str_starts_with( $p . '/', $dir . '/' ) || $real === $p || str_starts_with( $p . '/', $real . '/' ) ) { return false; } } return true; } /** * Random part of the default folder name (12 lower-case letters and digits). * * @return string */ public static function sub() { $sub = (string) get_option( self::SUB ); if ( ! preg_match( '/^[a-z0-9]{12}$/', $sub ) ) { // No option (a fresh install, or a database put back by other means): a folder of ours // already in wp-content is taken up again rather than left behind with its backups. $sub = self::find_sub(); if ( '' === $sub ) { $sub = strtolower( wp_generate_password( 12, false, false ) ); } update_option( self::SUB, $sub, false ); } return $sub; } /** * The random part of an existing wp-content/rollbakr-* folder, when the option is gone: the one * with the newest backup in it, else the newest folder. '' when there is none. * * @return string */ public static function find_sub() { $best = ''; $score = -1; foreach ( glob( self::normalize( WP_CONTENT_DIR ) . '/rollbakr-*', GLOB_ONLYDIR ) ?: array() as $dir ) { $candidate = substr( basename( $dir ), strlen( 'rollbakr-' ) ); if ( ! preg_match( '/^[a-z0-9]{12}$/', $candidate ) ) { continue; } $newest = 0; foreach ( glob( $dir . '/*/manifest.json' ) ?: array() as $manifest ) { $newest = max( $newest, (int) filemtime( $manifest ) ); } // A folder with backups wins over one without, whatever their ages. $this_score = $newest > 0 ? $newest + 4102444800 : (int) filemtime( $dir ); if ( $this_score > $score ) { $score = $this_score; $best = $candidate; } } return $best; } /** * Whether a folder holds nothing but what ROLLBAKR itself puts in a backup folder (the three * protection files, job.json, the records of finished jobs, an add-on's lock): no backup, no * half-made one, nothing of anybody else's. * * @param string $dir Folder. * @return bool */ public static function holds_only_own( $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 ) { continue; } if ( preg_match( '/^(.+)\.(done|failed|cancelled|restore|deleted)$/', $name, $m ) && self::is_valid_id( $m[1] ) ) { continue; } return false; } if ( ! in_array( $name, array( '.htaccess', 'index.php', 'web.config', 'job.json' ), true ) ) { return false; } } return true; } /** * Remove the backup folders of ours left behind in wp-content (rollbakr-* of an earlier random * name, nokosu-* of the pre-release version) when they hold no backup: only the protection files * and old records. The current folder, and any folder with a backup or anything else in it, stays. * * @return string[] The folders removed. */ public static function tidy_stale() { $content = self::normalize( WP_CONTENT_DIR ); // Never the folder in use, nor the default one (it is the one in use again once "Keep on the // server" with its own folder is switched off). $keep = array( rtrim( self::dir(), '/' ), $content . '/rollbakr-' . self::sub() ); $removed = array(); foreach ( array_merge( glob( $content . '/rollbakr-*', GLOB_ONLYDIR ) ?: array(), glob( $content . '/nokosu-*', GLOB_ONLYDIR ) ?: array() ) as $dir ) { $dir = self::normalize( $dir ); if ( in_array( $dir, $keep, true ) || is_link( $dir ) || ! preg_match( '/^(rollbakr|nokosu)-[a-z0-9]{12}$/', basename( $dir ) ) || ! self::holds_only_own( $dir ) ) { continue; } if ( self::wipe( $dir ) ) { $removed[] = $dir; } } return $removed; } /** * Remove one of those left-behind folders with its records (remove_tree() works inside the * current backup folder only). Links are not followed. * * @param string $dir Folder. * @return bool */ private static function wipe( $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_dir( $path ) && ! is_link( $path ) ) { self::wipe( $path ); } else { wp_delete_file( $path ); } } return @rmdir( $dir ); // phpcs:ignore WordPress.PHP.NoSilencedErrors, WordPress.WP.AlternativeFunctions } /** * This site's identifier (made once, kept forever). * * @return string */ public static function site_id() { $id = (string) get_option( self::SITE ); if ( ! preg_match( '/^[a-z0-9]{32}$/', $id ) ) { $id = strtolower( wp_generate_password( 32, false, false ) ); update_option( self::SITE, $id, false ); } return $id; } /** * Where the folder is configured to be: 'constant', 'setting' or 'default'. * * @return string */ public static function source() { if ( defined( 'ROLLBAKR_BACKUP_DIR' ) && self::is_allowed_dir( (string) ROLLBAKR_BACKUP_DIR ) ) { return 'constant'; } return self::is_allowed_dir( (string) Rollbakr_Settings::get( 'dir' ) ) ? 'setting' : 'default'; } /** * Absolute path of the backup folder, with a trailing slash. * * @return string */ public static function dir() { if ( null !== self::$pinned ) { return self::$pinned; } switch ( self::source() ) { case 'constant': $dir = (string) ROLLBAKR_BACKUP_DIR; break; case 'setting': $dir = (string) Rollbakr_Settings::get( 'dir' ); break; default: $dir = WP_CONTENT_DIR . '/rollbakr-' . self::sub(); } return self::normalize( $dir ) . '/'; } /** * The folder as shown on the screens: relative to the WordPress root when inside it, else absolute. * * @param string $dir Folder (default: dir()). * @return string */ public static function display_dir( $dir = '' ) { $dir = self::normalize( '' === $dir ? self::dir() : $dir ) . '/'; $root = self::normalize( ABSPATH ) . '/'; return str_starts_with( $dir, $root ) ? substr( $dir, strlen( $root ) ) : $dir; } /** * URL of the backup folder when it is inside the WordPress install, else '' (not reachable by URL). * * @param string $dir Folder (default: dir()). * @return string */ public static function url( $dir = '' ) { // Links are resolved on both sides: a folder that only looks outside the install is not outside. $dir = self::real( '' === $dir ? self::dir() : $dir ) . '/'; $content = self::real( WP_CONTENT_DIR ) . '/'; $root = self::real( ABSPATH ) . '/'; if ( str_starts_with( $dir, $content ) ) { return content_url( substr( $dir, strlen( $content ) ) ); } if ( str_starts_with( $dir, $root ) ) { return site_url( substr( $dir, strlen( $root ) ) ); } return ''; } /** * Whether a browser could reach a folder: it is inside the WordPress install (it has a URL), or * inside the web server's document root when that is known (WordPress in a sub folder of it). * Links are resolved on both sides. * * @param string $dir Folder (default: dir()). * @return bool */ public static function is_web_reachable( $dir = '' ) { $dir = self::real( '' === $dir ? self::dir() : $dir ) . '/'; if ( '' !== self::url( $dir ) ) { return true; } $root = self::document_root(); return '' !== $root && str_starts_with( $dir, $root . '/' ); } /** * The web server's document root, resolved, without a trailing slash; '' when not known (WP-CLI) * or not a folder. Remembered from the last request that knew it, like server(). * * @return string */ public static function document_root() { $root = isset( $_SERVER['DOCUMENT_ROOT'] ) ? sanitize_text_field( wp_unslash( $_SERVER['DOCUMENT_ROOT'] ) ) : ''; if ( '' === $root ) { $last = self::last_check(); $root = $last ? (string) ( $last['docroot'] ?? '' ) : ''; } if ( '' === $root || ! is_dir( $root ) ) { return ''; } $real = self::real( $root ); // A root that holds the install is only a root when it really contains it (a bogus value // such as "/" would make every folder "inside"). return '/' === $real ? '' : $real; } /** * A folder ROLLBAKR suggests for "Keep on the server": next to the install, outside the web root, * where the web server can write. ROLLBAKR_BACKUP_DIR when it is set. '' when no such place is found * (the administrator types one, or downloads instead). * * @return string Absolute path, normalized, or ''. */ public static function suggest_dir() { if ( defined( 'ROLLBAKR_BACKUP_DIR' ) && self::is_allowed_dir( (string) ROLLBAKR_BACKUP_DIR ) ) { return self::normalize( (string) ROLLBAKR_BACKUP_DIR ); } $parents = array( dirname( self::normalize( ABSPATH ) ) ); $root = self::document_root(); if ( '' !== $root ) { $parents[] = dirname( $root ); } foreach ( array_unique( $parents ) as $parent ) { if ( '' === $parent || '/' === $parent || ! is_dir( $parent ) ) { continue; } $candidate = $parent . '/rollbakr-backups'; if ( ! self::is_allowed_dir( $candidate ) || self::is_web_reachable( $candidate ) ) { continue; } if ( is_dir( $candidate ) ? wp_is_writable( $candidate ) : wp_is_writable( $parent ) ) { return $candidate; } } return ''; } /** * Create the folder and the files that block direct access on Apache, LiteSpeed and IIS. * * @return true|WP_Error */ public static function protect() { $dir = self::dir(); // Only the folder itself is made: a chain of parents would inherit permissions from wherever // it starts (world-writable under /tmp, for example). if ( ! is_dir( dirname( rtrim( $dir, '/' ) ) ) ) { return new WP_Error( 'rollbakr_mkdir', sprintf( /* translators: %s: folder */ __( 'The backup folder could not be created, because the folder above it does not exist: %s', 'rollbakr' ), $dir ) ); } if ( ! wp_mkdir_p( $dir ) ) { return new WP_Error( 'rollbakr_mkdir', sprintf( /* translators: %s: folder */ __( 'The backup folder could not be created: %s', 'rollbakr' ), $dir ) ); } if ( ! wp_is_writable( $dir ) ) { return new WP_Error( 'rollbakr_not_writable', sprintf( /* translators: %s: folder */ __( 'The backup folder is not writable: %s', 'rollbakr' ), $dir ) ); } @chmod( $dir, 0750 ); // phpcs:ignore WordPress.PHP.NoSilencedErrors, WordPress.WP.AlternativeFunctions $files = array( '.htaccess' => "# ROLLBAKR: nobody may fetch the backups through the web server.\n\n\tRequire all denied\n\n\n\tOrder deny,allow\n\tDeny from all\n\nOptions -Indexes\n", 'web.config' => "\n\n", 'index.php' => " $body ) { if ( ! file_exists( $dir . $name ) ) { file_put_contents( $dir . $name, $body ); // phpcs:ignore WordPress.WP.AlternativeFunctions @chmod( $dir . $name, 0640 ); // phpcs:ignore WordPress.PHP.NoSilencedErrors, WordPress.WP.AlternativeFunctions } } return true; } /** * Look at the backup folder and remember the result: can it be created and written, and (with * "keep on the server") is it outside the web root? No request is made to any URL. * * @param bool $force Check again even when a result is cached. * @return array{status:string,server:string,docroot:string,checked:int,dir:string,url:string,error:string} * status: ok (writable; and outside the web root when backups are kept on the server), * inside (a browser could reach it: not usable for keeping backups), error (the folder cannot be * created or written). */ public static function check( $force = false ) { $cached = self::last_check(); if ( ! $force && $cached && $cached['dir'] === self::dir() ) { return $cached; } $dir = self::dir(); $result = array( 'status' => 'ok', 'server' => self::server(), 'docroot' => self::document_root(), 'checked' => time(), 'dir' => $dir, 'url' => self::url(), 'error' => '', ); $ready = self::protect(); if ( is_wp_error( $ready ) ) { $result['status'] = 'error'; $result['error'] = $ready->get_error_message(); } elseif ( ! self::is_local() && self::is_web_reachable( $dir ) ) { $result['status'] = 'inside'; $result['error'] = __( 'This folder is inside the web root, where a browser could reach it. Backups are kept only in a folder outside the web root.', 'rollbakr' ); } else { // Really write a file: wp_is_writable() can be wrong about a folder (ACLs, a full disk). $probe = $dir . self::PROBE . strtolower( wp_generate_password( 8, false, false ) ) . '.txt'; if ( false === @file_put_contents( $probe, 'rollbakr' ) ) { // phpcs:ignore WordPress.PHP.NoSilencedErrors, WordPress.WP.AlternativeFunctions $result['status'] = 'error'; $result['error'] = sprintf( /* translators: %s: folder */ __( 'The backup folder is not writable: %s', 'rollbakr' ), $dir ); } else { wp_delete_file( $probe ); } } // Kept until the next check (not a transient), so a problem never disappears by itself. update_option( self::CHECK, $result, false ); return $result; } /** * Whether backups are kept on the server ('server') or downloaded and removed ('local'). * * @return bool True for 'local'. */ public static function is_local() { return 'local' === Rollbakr_Settings::get( 'destination' ); } /** * Whether a job may write to the folder now. With 'local' the folder only has to be writable * (backups wait there until they are downloaded and deleted); with 'server' the check must also * say it is outside the web root. * * @return true|WP_Error rollbakr_mkdir / rollbakr_not_writable / rollbakr_storage_unsafe. */ public static function gate() { $ready = self::protect(); if ( is_wp_error( $ready ) ) { return $ready; } if ( self::is_local() ) { return true; } if ( ! self::is_safe( self::check() ) ) { return new WP_Error( 'rollbakr_storage_unsafe', __( 'The backup folder cannot be used (it cannot be written, or a browser could reach it), so no backup is made.', 'rollbakr' ) ); } return true; } /** * Look at a folder somebody wants to use for "keep on the server", without saving anything: is it * allowed, can it be written, and is it outside the web root (where no browser can reach it)? * * @param string $dir Candidate folder (absolute path). * @return array{status:string,dir:string,message:string} * status: ok | inside | cannot_write | not_allowed. */ public static function probe_dir( $dir ) { $dir = self::normalize( $dir ); if ( '' === $dir || ! self::is_allowed_dir( $dir ) ) { return array( 'status' => 'not_allowed', 'dir' => $dir, 'message' => __( 'This folder cannot be used: it must be an absolute path, and not the WordPress folder itself (nor wp-content, plugins, themes, uploads or a folder above them).', 'rollbakr' ), ); } if ( ! is_dir( dirname( $dir ) ) ) { return array( 'status' => 'cannot_write', 'dir' => $dir, 'message' => __( 'The folder above this one does not exist. Create it first (or give a folder that exists).', 'rollbakr' ), ); } $made = ! is_dir( $dir ); $ok = wp_mkdir_p( $dir ) && wp_is_writable( $dir ); if ( $ok ) { $probe = $dir . '/' . self::PROBE . strtolower( wp_generate_password( 8, false, false ) ) . '.txt'; $ok = false !== file_put_contents( $probe, 'rollbakr' ); // phpcs:ignore WordPress.WP.AlternativeFunctions if ( $ok ) { wp_delete_file( $probe ); } } if ( $made && is_dir( $dir ) && array() === array_diff( (array) scandir( $dir ), array( '.', '..' ) ) ) { @rmdir( $dir ); // phpcs:ignore WordPress.PHP.NoSilencedErrors, WordPress.WP.AlternativeFunctions -- only the empty folder this probe made. } if ( ! $ok ) { return array( 'status' => 'cannot_write', 'dir' => $dir, 'message' => __( 'This folder cannot be written. Check that it exists and that the web server may write to it (its permissions).', 'rollbakr' ), ); } if ( self::is_web_reachable( $dir ) ) { return array( 'status' => 'inside', 'dir' => $dir, 'message' => __( 'This folder is inside the web root, where a browser could reach it. Give a folder outside it (one level above the WordPress folder, for example).', 'rollbakr' ), ); } return array( 'status' => 'ok', 'dir' => $dir, 'message' => '', // The mark says it ("A browser cannot reach it"); no line under it. ); } /** * The last result of check(), without checking. * * @return array{status:string,server:string,docroot:string,checked:int,dir:string,url:string,error:string}|null */ public static function last_check() { $result = get_option( self::CHECK ); return is_array( $result ) && isset( $result['status'], $result['dir'] ) ? $result : null; } /** * Check again when the last check is older than a day (called when the admin screens open). * * @return array{status:string,server:string,docroot:string,checked:int,dir:string,url:string,error:string}|null */ public static function recheck_daily() { // Once a day, whatever the destination: folders of ours left behind in wp-content go. if ( false === get_transient( 'rollbakr_tidied' ) ) { set_transient( 'rollbakr_tidied', 1, DAY_IN_SECONDS ); self::tidy_stale(); } $last = self::last_check(); if ( self::is_local() ) { // Nothing to check: backups are downloaded and removed, whatever the server does with the folder. return $last; } if ( ! $last || $last['dir'] !== self::dir() || (int) $last['checked'] < time() - DAY_IN_SECONDS ) { return self::check( true ); } return $last; } /** * Whether backups may be written: with 'local', always (they are downloaded and removed); with * 'server', when the check says ok. 'inside' and 'error' block them. * * @param array|null $check Result of check() (default: last_check()). * @return bool */ public static function is_safe( $check = null ) { if ( self::is_local() ) { return true; } $check = $check ?? self::last_check(); return $check && 'ok' === $check['status']; } /** * Web server family from SERVER_SOFTWARE: nginx, apache (also LiteSpeed), iis or other. * From WP-CLI the server is not known, so the last known value is kept. * * @return string */ public static function server() { $software = isset( $_SERVER['SERVER_SOFTWARE'] ) ? strtolower( sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) ) : ''; if ( '' === $software ) { $last = self::last_check(); return $last ? (string) ( $last['server'] ?? 'other' ) : 'other'; } if ( str_contains( $software, 'nginx' ) ) { return 'nginx'; } if ( str_contains( $software, 'apache' ) || str_contains( $software, 'litespeed' ) ) { return 'apache'; } if ( str_contains( $software, 'iis' ) ) { return 'iis'; } return 'other'; } /** * Free space on the disk holding the folder, in bytes, or null when unknown. * * @return int|null */ public static function free_space() { $dir = self::dir(); if ( ! is_dir( $dir ) || ! function_exists( 'disk_free_space' ) ) { return null; } $free = @disk_free_space( $dir ); // phpcs:ignore WordPress.PHP.NoSilencedErrors return false === $free ? null : (int) $free; } /** * Bytes used by everything in the folder. * * @return int */ public static function used_space() { return self::folder_size( self::dir() ); } /** * Size of a folder in bytes. * * @param string $dir Folder. * @return int */ public static function folder_size( $dir ) { if ( ! is_dir( $dir ) ) { return 0; } $size = 0; try { $it = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $dir, FilesystemIterator::SKIP_DOTS ), RecursiveIteratorIterator::LEAVES_ONLY, RecursiveIteratorIterator::CATCH_GET_CHILD ); foreach ( $it as $file ) { if ( $file->isFile() ) { $size += $file->getSize(); } } } catch ( Throwable $e ) { // A folder that cannot be read: count what could be seen. return $size; } return $size; } /** * Whether a string is a backup or job id made by new_id(): date, time and 6 random characters. * * @param string $id Id. * @return bool */ public static function is_valid_id( $id ) { return is_string( $id ) && 1 === preg_match( '/^\d{4}-\d{2}-\d{2}-\d{6}-[a-z0-9]{6}$/', $id ); } /** * A new id for a backup or a job, e.g. 2026-10-29-153012-a8f3k2 (site time). * * @return string */ public static function new_id() { return wp_date( 'Y-m-d-His' ) . '-' . strtolower( wp_generate_password( 6, false, false ) ); } /** * Delete a folder and everything in it. Refuses anything outside the backup folder. * * @param string $dir Folder. * @param float|null $deadline Stop (and return false) once this time is reached, leaving the rest * for another call. Null = remove everything in one go. * @return bool True when the folder is gone. */ public static function remove_tree( $dir, $deadline = null ) { $dir = self::normalize( $dir ) . '/'; $base = self::dir(); if ( $dir === $base || ! str_starts_with( $dir, $base ) ) { return false; } if ( ! is_dir( $dir ) ) { return true; } // A link, or a path that resolves outside the folder through links, is not removed. $real = realpath( $dir ); $real_base = realpath( $base ); if ( is_link( rtrim( $dir, '/' ) ) || false === $real || false === $real_base || ! str_starts_with( wp_normalize_path( $real ) . '/', wp_normalize_path( $real_base ) . '/' ) ) { return false; } try { $it = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $dir, FilesystemIterator::SKIP_DOTS ), RecursiveIteratorIterator::CHILD_FIRST ); foreach ( $it as $file ) { if ( null !== $deadline && microtime( true ) >= $deadline ) { return false; } if ( $file->isDir() && ! $file->isLink() ) { @rmdir( $file->getPathname() ); // phpcs:ignore WordPress.PHP.NoSilencedErrors, WordPress.WP.AlternativeFunctions } else { wp_delete_file( $file->getPathname() ); } } } catch ( Throwable $e ) { // A folder inside that cannot be read: what could be removed is gone, the rest stays. return false; } return @rmdir( $dir ); // phpcs:ignore WordPress.PHP.NoSilencedErrors, WordPress.WP.AlternativeFunctions } }