WordPress.org

Make WordPress Core

Ticket #38231: 38231.2.diff

File 38231.2.diff, 982 bytes (added by psrpinto, 4 months ago)

Refactor according to @dd32's suggestions

  • src/wp-admin/includes/file.php

    diff --git src/wp-admin/includes/file.php src/wp-admin/includes/file.php
    index 98e0f4962c..4889b527d6 100644
    function download_url( $url, $timeout = 300, $signature_verification = false ) { 
    11411141                return new WP_Error( 'http_404', trim( wp_remote_retrieve_response_message( $response ) ), $data );
    11421142        }
    11431143
     1144        $content_disposition = wp_remote_retrieve_header( $response, 'Content-Disposition' );
     1145
     1146        if ( preg_match( '/filename=("?)([^ ]+)\1/', $content_disposition, $matches ) ) {
     1147                $tmpfname_disposition = wp_tempnam( $matches[2] );
     1148
     1149                if ( $tmpfname_disposition && rename( $tmpfname, $tmpfname_disposition ) ) {
     1150                        $tmpfname = $tmpfname_disposition;
     1151                }
     1152
     1153                if ( $tmpfname !== $tmpfname_disposition && file_exists( $tmpfname_disposition ) ) {
     1154                        unlink( $tmpfname_disposition );
     1155                }
     1156        }
     1157
    11441158        $content_md5 = wp_remote_retrieve_header( $response, 'content-md5' );
    11451159
    11461160        if ( $content_md5 ) {