Improve Filesystem method choice for 'direct'; introduce FS_METHOD constant, props DD32, fixes #9936

git-svn-id: https://develop.svn.wordpress.org/trunk@11454 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz 2009-05-25 10:39:21 +00:00
parent 1b7643d281
commit b6d0536c00
1 changed files with 11 additions and 8 deletions

View File

@ -626,18 +626,21 @@ function WP_Filesystem( $args = false ) {
* @return unknown * @return unknown
*/ */
function get_filesystem_method($args = array()) { function get_filesystem_method($args = array()) {
$method = false; $method = defined('FS_METHOD') ? FS_METHOD : false; //Please ensure that this is either 'direct', 'ssh', 'ftpext' or 'ftpsockets'
if( function_exists('getmyuid') && function_exists('fileowner') ){
$temp_file = wp_tempnam(); if( ! $method && function_exists('getmyuid') && function_exists('fileowner') ){
if ( getmyuid() == fileowner($temp_file) ) $temp_file_name = ABSPATH . '.' . time();
$method = 'direct'; $temp_handle = @fopen($temp_file_name, 'w');
unlink($temp_file); if ( $temp_handle && getmyuid() == fileowner($temp_file_name) )
} $method = 'direct';
@fclose($temp_handle);
unlink($temp_file_name);
}
if ( ! $method && isset($args['connection_type']) && 'ssh' == $args['connection_type'] && extension_loaded('ssh2') && extension_loaded('sockets') ) $method = 'ssh2'; if ( ! $method && isset($args['connection_type']) && 'ssh' == $args['connection_type'] && extension_loaded('ssh2') && extension_loaded('sockets') ) $method = 'ssh2';
if ( ! $method && extension_loaded('ftp') ) $method = 'ftpext'; 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 if ( ! $method && ( extension_loaded('sockets') || function_exists('fsockopen') ) ) $method = 'ftpsockets'; //Sockets: Socket extension; PHP Mode: FSockopen / fwrite / fread
return apply_filters('filesystem_method', $method); return apply_filters('filesystem_method', $method, $args);
} }
/** /**