when FS_METHOD = ‘direct’ is chosen?

Here’s the code from wp-admin/includes/file.php:

if ( ! $method && function_exists('getmyuid') && function_exists('fileowner') ){
    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);
    $temp_file_name = $context . 'temp-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);
    }
}

The test appears to be

  1. Can we create a temporary file in the wp-content or wp-content/languages directory?
  2. Does that file belong to the current Unix user, i.e. there’s no setuid on wp-content?

It only executes this check if we didn’t specify an FS_METHOD ourselves, and if the necessary filesystem calls to check #2 are available. The temporary file is cleaned up afterwards.

Leave a Comment