WP_Upgrader::delete_temp_backup │ public │ WP 6.3.0

Deletes a temporary backup.

Метод класса: WP_Upgrader{}

Хуков нет.

Возвращает

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

Использование

$WP_Upgrader = new WP_Upgrader();
$WP_Upgrader->delete_temp_backup( $temp_backups );
$temp_backups(array[])

An array of temporary backups.

По умолчанию: array()

  • ...$0(массив)
    Information about the backup.

    • dir(строка)
      The temporary backup location in the upgrade-temp-backup directory.

    • slug(строка)
      The item's slug.

    • src(строка)
      The directory where the original is stored. For example, WP_PLUGIN_DIR.

Заметки

Global. WP_Filesystem_Base. $wp_filesystem WordPress filesystem subclass.

Список изменений

С версии 6.3.0 Введена.
С версии 6.6.0 Added the $temp_backups parameter.

Код WP_Upgrader::delete_temp_backup() WP 7.1.2

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;
}