Make WordPress Core

Changeset 11454


Ignore:
Timestamp:
05/25/2009 10:39:21 AM (16 years ago)
Author:
azaozz
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/file.php

    r11450 r11454  
    627627 */
    628628function get_filesystem_method($args = array()) {
    629     $method = false;
    630     if( function_exists('getmyuid') && function_exists('fileowner') ){
    631         $temp_file = wp_tempnam();
    632         if ( getmyuid() == fileowner($temp_file) )
    633             $method = 'direct';
    634         unlink($temp_file);
    635     }
     629    $method = defined('FS_METHOD') ? FS_METHOD : false; //Please ensure that this is either 'direct', 'ssh', 'ftpext' or 'ftpsockets'
     630
     631    if( ! $method && function_exists('getmyuid') && function_exists('fileowner') ){
     632        $temp_file_name = ABSPATH . '.' . time();
     633        $temp_handle = @fopen($temp_file_name, 'w');
     634        if ( $temp_handle && getmyuid() == fileowner($temp_file_name) )
     635            $method = 'direct';
     636        @fclose($temp_handle);
     637        unlink($temp_file_name);
     638    }
    636639
    637640    if ( ! $method && isset($args['connection_type']) && 'ssh' == $args['connection_type'] && extension_loaded('ssh2') && extension_loaded('sockets') ) $method = 'ssh2';
    638641    if ( ! $method && extension_loaded('ftp') ) $method = 'ftpext';
    639642    if ( ! $method && ( extension_loaded('sockets') || function_exists('fsockopen') ) ) $method = 'ftpsockets'; //Sockets: Socket extension; PHP Mode: FSockopen / fwrite / fread
    640     return apply_filters('filesystem_method', $method);
     643    return apply_filters('filesystem_method', $method, $args);
    641644}
    642645
Note: See TracChangeset for help on using the changeset viewer.