623c623
<  * {@internal Missing Short Description}}
---
>  * Determines how files from the wordpress-install should be accessed.
632c632,638
< 	$method = defined('FS_METHOD') ? FS_METHOD : false; //Please ensure that this is either 'direct', 'ssh', 'ftpext' or 'ftpsockets'
---
> 	$method = false;
> 	if ( ! $context )
> 		$context = WP_CONTENT_DIR;
> 
> 	if ( ! $method && defined('FS_METHOD') ) {
> 		$method = FS_METHOD; //Please ensure that this is either 'direct', 'ssh', 'ftpext' or 'ftpsockets'
> 	}
634,636c640,644
< 	if( ! $method && function_exists('getmyuid') && function_exists('fileowner') ){
< 		if ( !$context )
< 			$context = WP_CONTENT_DIR;
---
> 	if ( ! $method
> 		&& is_writable($context)
> 		&& function_exists('fileowner')
> 		&& function_exists('filegroup')
> 	) {
638,644c646,660
< 		$temp_file_name = $context . '.write-test-' . time();
< 		$temp_handle = @fopen($temp_file_name, 'w');
< 		if ( $temp_handle ) {
< 			if ( getmyuid() == fileowner($temp_file_name) )
< 				$method = 'direct';
< 			@fclose($temp_handle);
< 			unlink($temp_file_name);
---
> 		$owner = @fileowner($context);
> 		$group = @filegroup($context);
> 		if ( false !== $owner && false !== $group ) {
> 			$temp_file_name = $context . 'temp-write-test-' . time();
> 			$temp_handle = @fopen($temp_file_name, 'w');
> 			if ( $temp_handle ) {
> 				$php_owner = @fileowner($temp_file_name);
> 				$php_group = @filegroup($temp_file_name);
> 				if ( $php_owner === $owner
> 					|| ( $php_owner === $group && $php_group === $group )
> 				) // Success, direct-access seems possible
> 					$method = 'direct';
> 				@fclose($temp_handle);
> 				@unlink($temp_file_name);
> 			}
646c662
<  	}
---
> 	}
650a667
> 
