WordPress.org

Make WordPress Core

Ticket #9936: 9936.4.patch

File 9936.4.patch, 4.0 KB (added by azaozz, 11 years ago)

Possible patch

  • wp-admin/includes/class-wp-upgrader.php

     
    720720                return $this->__construct($args);
    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        }
    726726
     
    734734
    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
    742743        function header() {
  • wp-admin/includes/file.php

     
    583583 * @param unknown_type $args
    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 )
    594594                return false;
     
    623623 * @since unknown
    624624 *
    625625 * @param unknown_type $args
     626 * @param string $context Full path to the directory that is tested for being writable.
    626627 * @return unknown
    627628 */
    628 function get_filesystem_method($args = array()) {
     629function get_filesystem_method($args = array(), $context = false) {
    629630        $method = defined('FS_METHOD') ? FS_METHOD : false; //Please ensure that this is either 'direct', 'ssh', 'ftpext' or 'ftpsockets'
    630631
    631632        if( ! $method && function_exists('getmyuid') && function_exists('fileowner') ){
    632                 $temp_file_name = ABSPATH . '.' . time();
     633                if ( !$context )
     634                        $context = WP_CONTENT_DIR;
     635                $temp_file_name = $context . '.write-test-' . time();
    633636                $temp_handle = @fopen($temp_file_name, 'w');
    634637                if ( $temp_handle ) {
    635638                        if ( getmyuid() == fileowner($temp_file_name) )
     
    655658 * @param unknown_type $error
    656659 * @return unknown
    657660 */
    658 function request_filesystem_credentials($form_post, $type = '', $error = false) {
    659         $req_cred = apply_filters('request_filesystem_credentials', '', $form_post, $type, $error);
     661function request_filesystem_credentials($form_post, $type = '', $error = false, $context = false) {
     662        $req_cred = apply_filters('request_filesystem_credentials', '', $form_post, $type, $error, $context);
    660663        if ( '' !== $req_cred )
    661664                return $req_cred;
    662665
    663666        if ( empty($type) )
    664                 $type = get_filesystem_method();
     667                $type = get_filesystem_method(array(), $context);
    665668
    666669        if ( 'direct' == $type )
    667670                return true;
  • wp-admin/update-core.php

     
    142142        else
    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
    148148        $version = isset( $_POST['version'] )? $_POST['version'] : false;
     
    152152                return;
    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        }
    159159?>