_wp_delete_all_temp_backups()
Deletes all contents in the temporary backup directory.
Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.
No Hooks.
Returns
null. Nothing (null).
Usage
_wp_delete_all_temp_backups();
Notes
- Global. WP_Filesystem_Base.
$wp_filesystemWordPress filesystem subclass.
Changelog
| Since 6.3.0 | Introduced. |
_wp_delete_all_temp_backups() wp delete all temp backups code WP 7.0
function _wp_delete_all_temp_backups() {
global $wp_filesystem;
if ( ! function_exists( 'WP_Filesystem' ) ) {
require_once ABSPATH . 'wp-admin/includes/file.php';
}
ob_start();
$credentials = request_filesystem_credentials( '' );
ob_end_clean();
if ( false === $credentials || ! WP_Filesystem( $credentials ) ) {
wp_trigger_error( __FUNCTION__, __( 'Could not access filesystem.' ) );
return;
}
if ( ! $wp_filesystem->wp_content_dir() ) {
wp_trigger_error(
__FUNCTION__,
/* translators: %s: Directory name. */
sprintf( __( 'Unable to locate WordPress content directory (%s).' ), 'wp-content' )
);
return;
}
$temp_backup_dir = $wp_filesystem->wp_content_dir() . 'upgrade-temp-backup/';
$dirlist = $wp_filesystem->dirlist( $temp_backup_dir );
$dirlist = $dirlist ? $dirlist : array();
foreach ( array_keys( $dirlist ) as $dir ) {
if ( '.' === $dir || '..' === $dir ) {
continue;
}
$wp_filesystem->delete( $temp_backup_dir . $dir, true );
}
}