# get_filesystem_method()

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

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

## Сигнатура

```php
get_filesystem_method( array $args = array(), string $context = '', bool $allow_relaxed_file_ownership = false ): string
```

## Описание

Приоритет транспортов таков: Direct, SSH2, FTP PHP Extension, FTP Sockets (через класс Sockets или fsockopen()). Допустимые значения для них: ‘direct’, ‘ssh2’, ‘ftpext’ или ‘ftpsockets’.
Возвращаемое значение можно переопределить, задав константу FS_METHOD в wp-config.php или отфильтровав через ‘filesystem_method’.

## Параметры

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

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

`string`

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

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

```php
function get_filesystem_method( $args = array(), $context = '', $allow_relaxed_file_ownership = false ) {
	// Please ensure that this is either 'direct', 'ssh2', 'ftpext', or 'ftpsockets'.
	$method = defined( 'FS_METHOD' ) ? FS_METHOD : false;

	if ( ! $context ) {
		$context = WP_CONTENT_DIR;
	}

	// If the directory doesn't exist (wp-content/languages) then use the parent directory as we'll create it.
	if ( WP_LANG_DIR === $context && ! is_dir( $context ) ) {
		$context = dirname( $context );
	}

	$context = trailingslashit( $context );

	if ( ! $method ) {

		$temp_file_name = $context . 'temp-write-test-' . str_replace( '.', '-', uniqid( '', true ) );
		$temp_handle    = @fopen( $temp_file_name, 'w' );
		if ( $temp_handle ) {

			// Attempt to determine the file owner of the WordPress files, and that of newly created files.
			$wp_file_owner   = false;
			$temp_file_owner = false;
			if ( function_exists( 'fileowner' ) ) {
				$wp_file_owner   = @fileowner( __FILE__ );
				$temp_file_owner = @fileowner( $temp_file_name );
			}

			if ( false !== $wp_file_owner && $wp_file_owner === $temp_file_owner ) {
				/*
				 * WordPress is creating files as the same owner as the WordPress files,
				 * this means it's safe to modify & create new files via PHP.
				 */
				$method                                  = 'direct';
				$GLOBALS['_wp_filesystem_direct_method'] = 'file_owner';
			} elseif ( $allow_relaxed_file_ownership ) {
				/*
				 * The $context directory is writable, and $allow_relaxed_file_ownership is set,
				 * this means we can modify files safely in this directory.
				 * This mode doesn't create new files, only alter existing ones.
				 */
				$method                                  = 'direct';
				$GLOBALS['_wp_filesystem_direct_method'] = 'relaxed_ownership';
			}

			fclose( $temp_handle );
			@unlink( $temp_file_name );
		}
	}

	if ( ! $method && isset( $args['connection_type'] ) && 'ssh' === $args['connection_type'] && extension_loaded( 'ssh2' ) ) {
		$method = 'ssh2';
	}
	if ( ! $method && extension_loaded( 'ftp' ) ) {
		$method = 'ftpext';
	}
	if ( ! $method && ( extension_loaded( 'sockets' ) || function_exists( 'fsockopen' ) ) ) {
		$method = 'ftpsockets'; // Sockets: Socket extension; PHP Mode: FSockopen / fwrite / fread.
	}

	/**
	 * Filters the filesystem method to use.
	 *
	 * @since 2.6.0
	 *
	 * @param string $method                       Filesystem method to return.
	 * @param array  $args                         An array of connection details for the method.
	 * @param string $context                      Full path to the directory that is tested for being writable.
	 * @param bool   $allow_relaxed_file_ownership Whether to allow Group/World writable.
	 */
	return apply_filters( 'filesystem_method', $method, $args, $context, $allow_relaxed_file_ownership );
}
```

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

- 2.5.0 — Introduced.

## Связанные

Использует: [`trailingslashit`](https://chugunov.pro/api-wordpress/functions/trailingslashit/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/).
Используется в: `WP_REST_Plugins_Controller::is_filesystem_available`, `WP_Customize_Manager::customize_pane_settings`, [`wp_print_request_filesystem_credentials_modal`](https://chugunov.pro/api-wordpress/functions/wp_print_request_filesystem_credentials_modal/), [`request_filesystem_credentials`](https://chugunov.pro/api-wordpress/functions/request_filesystem_credentials/), [`WP_Filesystem`](https://chugunov.pro/api-wordpress/functions/wp_filesystem/).

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