Description
The priority of the transports are: Direct, SSH2, FTP PHP Extension, FTP Sockets (Via Sockets class, or fsockopen()
). Valid values for these are: ‘direct’, ‘ssh2’, ‘ftpext’ or ‘ftpsockets’.
The return value can be overridden by defining the FS_METHOD
constant in wp-config.php
, or filtering via ‘filesystem_method’.
Parameters
- $args
-
(array) (Optional) Connection details.
Default value: array()
- $context
-
(string) (Optional) Full path to the directory that is tested for being writable.
Default value: ''
- $allow_relaxed_file_ownership
-
(bool) (Optional) Whether to allow Group/World writable.
Default value: false
Return
(string) The transport to use, see description for valid return values.
Source
File: wp-admin/includes/file.php
function get_filesystem_method( $args = array(), $context = '', $allow_relaxed_file_ownership = false ) {
$method = defined( 'FS_METHOD' ) ? FS_METHOD : false;
if ( ! $context ) {
$context = WP_CONTENT_DIR;
}
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 ) {
$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 ) {
$method = 'direct';
$GLOBALS['_wp_filesystem_direct_method'] = 'file_owner';
} elseif ( $allow_relaxed_file_ownership ) {
$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';
}
return apply_filters( 'filesystem_method', $method, $args, $context, $allow_relaxed_file_ownership );
}
Changelog
Version | Description |
2.5.0 | Introduced. |