W3cubDocs

/WordPress

WP_Upgrader::delete_temp_backup( array[] $temp_backups = array() ): bool|WP_Error

Deletes a temporary backup.

Parameters

$temp_backupsarray[]optional
An array of temporary backups.
  • ...$0 array
    Information about the backup.
    • dir string
      The temporary backup location in the upgrade-temp-backup directory.
    • slug string
      The item’s slug.
    • src string
      The directory where the original is stored. For example, WP_PLUGIN_DIR.

    Default:array()

    Return

    bool|WP_Error True on success, false on early exit, otherwise WP_Error.

    Source

    public function delete_temp_backup( array $temp_backups = array() ) {
    	global $wp_filesystem;
    
    	$errors = new WP_Error();
    
    	if ( empty( $temp_backups ) ) {
    		$temp_backups = $this->temp_backups;
    	}
    
    	foreach ( $temp_backups as $args ) {
    		if ( empty( $args['slug'] ) || empty( $args['dir'] ) ) {
    			return false;
    		}
    
    		if ( ! $wp_filesystem->wp_content_dir() ) {
    			$errors->add( 'fs_no_content_dir', $this->strings['fs_no_content_dir'] );
    			return $errors;
    		}
    
    		$temp_backup_dir = $wp_filesystem->wp_content_dir() . "upgrade-temp-backup/{$args['dir']}/{$args['slug']}";
    
    		if ( ! $wp_filesystem->delete( $temp_backup_dir, true ) ) {
    			$errors->add(
    				'temp_backup_delete_failed',
    				sprintf( $this->strings['temp_backup_delete_failed'], $args['slug'] )
    			);
    			continue;
    		}
    	}
    
    	return $errors->has_errors() ? $errors : true;
    }
    

    Changelog

    Version Description
    6.6.0 Added the $temp_backups parameter.
    6.3.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_upgrader/delete_temp_backup