# WP_Filesystem()

URL: https://chugunov.pro/api-wordpress/functions/wp_filesystem/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 2.5.0.

## Сигнатура

```php
WP_Filesystem( array|false $args = false, string|false $context = false, bool $allow_relaxed_file_ownership = false ): bool|null
```

## Описание

Подключает выбранный транспорт и пытается установить соединение.
Плагины могут добавлять дополнительные транспорты и заставлять WordPress использовать их, возвращая имя файла через фильтр ‘filesystem_method_file’.

## Параметры

- `$args` `array|false` — необязательный, по умолчанию `false`. Аргументы подключения. Передаются напрямую в классы WP_Filesystem_*().
- `$context` `string|false` — необязательный, по умолчанию `false`. Контекст для get_filesystem_method() .
- `$allow_relaxed_file_ownership` `bool` — необязательный, по умолчанию `false`. Разрешать ли запись для группы и всех пользователей.

## Возвращаемое значение

`bool|null`

## Исходный код

Файл: `wp-admin/includes/file.php:2169`

```php
function WP_Filesystem( $args = false, $context = false, $allow_relaxed_file_ownership = false ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
	global $wp_filesystem;

	require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php';

	$method = get_filesystem_method( $args, $context, $allow_relaxed_file_ownership );

	if ( ! $method ) {
		return false;
	}

	if ( ! class_exists( "WP_Filesystem_$method" ) ) {

		/**
		 * Filters the path for a specific filesystem method class file.
		 *
		 * @since 2.6.0
		 *
		 * @see get_filesystem_method()
		 *
		 * @param string $path   Path to the specific filesystem method class file.
		 * @param string $method The filesystem method to use.
		 */
		$abstraction_file = apply_filters( 'filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method );

		if ( ! file_exists( $abstraction_file ) ) {
			return null;
		}

		require_once $abstraction_file;
	}
	$method = "WP_Filesystem_$method";

	$wp_filesystem = new $method( $args );

	/*
	 * Define the timeouts for the connections. Only available after the constructor is called
	 * to allow for per-transport overriding of the default.
	 */
	if ( ! defined( 'FS_CONNECT_TIMEOUT' ) ) {
		define( 'FS_CONNECT_TIMEOUT', 30 ); // 30 seconds.
	}
	if ( ! defined( 'FS_TIMEOUT' ) ) {
		define( 'FS_TIMEOUT', 30 ); // 30 seconds.
	}

	if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {
		return false;
	}

	if ( ! $wp_filesystem->connect() ) {
		return false; // There was an error connecting to the server.
	}

	// Set the permission constants if not already set.
	if ( ! defined( 'FS_CHMOD_DIR' ) ) {
		define( 'FS_CHMOD_DIR', ( fileperms( ABSPATH ) & 0777 | 0755 ) );
	}
	if ( ! defined( 'FS_CHMOD_FILE' ) ) {
		define( 'FS_CHMOD_FILE', ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 ) );
	}

	return true;
}
```

## История изменений

- 2.5.0 — Introduced.

## Связанные

Использует: [`get_filesystem_method`](https://chugunov.pro/api-wordpress/functions/get_filesystem_method/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/), [`is_wp_error`](https://chugunov.pro/api-wordpress/functions/is_wp_error/).
Используется в: [`_wp_delete_all_temp_backups`](https://chugunov.pro/api-wordpress/functions/_wp_delete_all_temp_backups/), `WP_Site_Health::get_test_update_temp_backup_writable`, `WP_Site_Health_Auto_Updates::test_all_files_writable`, [`wp_ajax_delete_plugin`](https://chugunov.pro/api-wordpress/functions/wp_ajax_delete_plugin/), [`wp_ajax_delete_theme`](https://chugunov.pro/api-wordpress/functions/wp_ajax_delete_theme/), `WP_Upgrader::fs_connect`, `WP_Upgrader::maintenance_mode`, [`delete_theme`](https://chugunov.pro/api-wordpress/functions/delete_theme/), [`delete_plugins`](https://chugunov.pro/api-wordpress/functions/delete_plugins/), [`do_core_upgrade`](https://chugunov.pro/api-wordpress/functions/do_core_upgrade/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/wp_filesystem/
