WordPress.org

Make WordPress Core

Changeset 11499


Ignore:
Timestamp:
05/31/09 21:08:03 (6 years ago)
Author:
azaozz
Message:

Test writability of ABSPATH when upgrading core or WP_PLUGIN_DIR when installing/updating themes and plugins, fixes #9936

Location:
trunk/wp-admin
Files:
3 edited

Legend:

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

    r11450 r11499  
    721721    } 
    722722    function __construct($args = array()) { 
    723         $defaults = array( 'url' => '', 'nonce' => '', 'title' => '' ); 
     723        $defaults = array( 'url' => '', 'nonce' => '', 'title' => '', 'context' => false ); 
    724724        $this->options = wp_parse_args($args, $defaults); 
    725725    } 
     
    735735    function request_filesystem_credentials($error = false) { 
    736736        $url = $this->options['url']; 
     737        $context = $this->options['context']; 
    737738        if ( !empty($this->options['nonce']) ) 
    738739            $url = wp_nonce_url($url, $this->options['nonce']); 
    739         return request_filesystem_credentials($url, '', $error); //Possible to bring inline, Leaving as0is for now. 
     740        return request_filesystem_credentials($url, '', $error, $context); //Possible to bring inline, Leaving as is for now. 
    740741    } 
    741742 
  • trunk/wp-admin/includes/file.php

    r11495 r11499  
    584584 * @return unknown 
    585585 */ 
    586 function WP_Filesystem( $args = false ) { 
     586function WP_Filesystem( $args = false, $context = false ) { 
    587587    global $wp_filesystem; 
    588588 
    589589    require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php'); 
    590590 
    591     $method = get_filesystem_method($args); 
     591    $method = get_filesystem_method($args, $context); 
    592592 
    593593    if ( ! $method ) 
     
    626626 * 
    627627 * @param unknown_type $args 
    628  * @return unknown 
    629  */ 
    630 function get_filesystem_method($args = array()) { 
     628 * @param string $context Full path to the directory that is tested for being writable. 
     629 * @return unknown 
     630 */ 
     631function get_filesystem_method($args = array(), $context = false) { 
    631632    $method = defined('FS_METHOD') ? FS_METHOD : false; //Please ensure that this is either 'direct', 'ssh', 'ftpext' or 'ftpsockets' 
    632633 
    633634    if( ! $method && function_exists('getmyuid') && function_exists('fileowner') ){ 
    634         $temp_file_name = ABSPATH . '.' . time(); 
     635        if ( !$context ) 
     636            $context = WP_CONTENT_DIR; 
     637        $context = trailingslashit($context); 
     638        $temp_file_name = $context . '.write-test-' . time(); 
    635639        $temp_handle = @fopen($temp_file_name, 'w'); 
    636640        if ( $temp_handle ) { 
     
    658662 * @return unknown 
    659663 */ 
    660 function request_filesystem_credentials($form_post, $type = '', $error = false) { 
    661     $req_cred = apply_filters('request_filesystem_credentials', '', $form_post, $type, $error); 
     664function request_filesystem_credentials($form_post, $type = '', $error = false, $context = false) { 
     665    $req_cred = apply_filters('request_filesystem_credentials', '', $form_post, $type, $error, $context); 
    662666    if ( '' !== $req_cred ) 
    663667        return $req_cred; 
    664668 
    665669    if ( empty($type) ) 
    666         $type = get_filesystem_method(); 
     670        $type = get_filesystem_method(array(), $context); 
    667671 
    668672    if ( 'direct' == $type ) 
  • trunk/wp-admin/update-core.php

    r11383 r11499  
    143143        $url = 'update-core.php?action=do-core-upgrade'; 
    144144    $url = wp_nonce_url($url, 'upgrade-core'); 
    145     if ( false === ($credentials = request_filesystem_credentials($url)) ) 
     145    if ( false === ($credentials = request_filesystem_credentials($url, '', false, ABSPATH)) ) 
    146146        return; 
    147147 
     
    153153 
    154154 
    155     if ( ! WP_Filesystem($credentials) ) { 
    156         request_filesystem_credentials($url, '', true); //Failed to connect, Error and request again 
     155    if ( ! WP_Filesystem($credentials, ABSPATH) ) { 
     156        request_filesystem_credentials($url, '', true, ABSPATH); //Failed to connect, Error and request again 
    157157        return; 
    158158    } 
Note: See TracChangeset for help on using the changeset viewer.