Title: _wp_delete_all_temp_backups
Published: August 8, 2023
Last modified: May 20, 2026

---

# _wp_delete_all_temp_backups()

## In this article

 * [Source](https://developer.wordpress.org/reference/functions/_wp_delete_all_temp_backups/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/_wp_delete_all_temp_backups/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/_wp_delete_all_temp_backups/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/_wp_delete_all_temp_backups/?output_format=md#wp--skip-link--target)

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

Deletes all contents in the temporary backup directory.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/_wp_delete_all_temp_backups/?output_format=md#source)󠁿

    ```php
    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 );
    	}
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/update.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/update.php#L1149)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/update.php#L1149-L1185)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/_wp_delete_all_temp_backups/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_trigger_error()](https://developer.wordpress.org/reference/functions/wp_trigger_error/)`wp-includes/functions.php` |

Generates a user-level error/warning/notice/deprecation message.

  | 
| [request_filesystem_credentials()](https://developer.wordpress.org/reference/functions/request_filesystem_credentials/)`wp-admin/includes/file.php` |

Displays a form to the user to request for their FTP/SSH details in order to connect to the filesystem.

  | 
| [WP_Filesystem()](https://developer.wordpress.org/reference/functions/wp_filesystem/)`wp-admin/includes/file.php` |

Initializes and connects the WordPress Filesystem Abstraction classes.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/_wp_delete_all_temp_backups/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/_wp_delete_all_temp_backups/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/_wp_delete_all_temp_backups/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.3.0](https://developer.wordpress.org/reference/since/6.3.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2F_wp_delete_all_temp_backups%2F)
before being able to contribute a note or feedback.