Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (7 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

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

    r42246 r42343  
    106106    if ( ! empty( $home ) && 0 !== strcasecmp( $home, $siteurl ) ) {
    107107        $wp_path_rel_to_home = str_ireplace( $home, '', $siteurl ); /* $siteurl - $home */
    108         $pos = strripos( str_replace( '\\', '/', $_SERVER['SCRIPT_FILENAME'] ), trailingslashit( $wp_path_rel_to_home ) );
    109         $home_path = substr( $_SERVER['SCRIPT_FILENAME'], 0, $pos );
    110         $home_path = trailingslashit( $home_path );
     108        $pos                 = strripos( str_replace( '\\', '/', $_SERVER['SCRIPT_FILENAME'] ), trailingslashit( $wp_path_rel_to_home ) );
     109        $home_path           = substr( $_SERVER['SCRIPT_FILENAME'], 0, $pos );
     110        $home_path           = trailingslashit( $home_path );
    111111    } else {
    112112        $home_path = ABSPATH;
     
    157157                $files2 = list_files( $folder . $file, $levels - 1 );
    158158                if ( $files2 ) {
    159                     $files = array_merge($files, $files2 );
     159                    $files = array_merge( $files, $files2 );
    160160                } else {
    161161                    $files[] = $folder . $file . '/';
     
    368368    }
    369369
    370     $plugin = null;
    371     $theme = null;
     370    $plugin    = null;
     371    $theme     = null;
    372372    $real_file = null;
    373373    if ( ! empty( $args['plugin'] ) ) {
     
    435435                    break;
    436436                case 'css':
    437                     $style_files = $theme->get_files( 'css', -1 );
     437                    $style_files                = $theme->get_files( 'css', -1 );
    438438                    $allowed_files['style.css'] = $style_files['style.css'];
    439                     $allowed_files = array_merge( $allowed_files, $style_files );
     439                    $allowed_files              = array_merge( $allowed_files, $style_files );
    440440                    break;
    441441                default:
     
    494494    if ( $is_active && 'php' === $extension ) {
    495495
    496         $scrape_key = md5( rand() );
    497         $transient = 'scrape_key_' . $scrape_key;
     496        $scrape_key   = md5( rand() );
     497        $transient    = 'scrape_key_' . $scrape_key;
    498498        $scrape_nonce = strval( rand() );
    499499        set_transient( $transient, $scrape_nonce, 60 ); // It shouldn't take more than 60 seconds to make the two loopback requests.
    500500
    501         $cookies = wp_unslash( $_COOKIE );
     501        $cookies       = wp_unslash( $_COOKIE );
    502502        $scrape_params = array(
    503             'wp_scrape_key' => $scrape_key,
     503            'wp_scrape_key'   => $scrape_key,
    504504            'wp_scrape_nonce' => $scrape_nonce,
    505505        );
    506         $headers = array(
     506        $headers       = array(
    507507            'Cache-Control' => 'no-cache',
    508508        );
     
    520520
    521521        $needle_start = "###### wp_scraping_result_start:$scrape_key ######";
    522         $needle_end = "###### wp_scraping_result_end:$scrape_key ######";
     522        $needle_end   = "###### wp_scraping_result_end:$scrape_key ######";
    523523
    524524        // Attempt loopback request to editor to see if user just whitescreened themselves.
     
    529529                array(
    530530                    'theme' => $stylesheet,
    531                     'file' => $file,
     531                    'file'  => $file,
    532532                ),
    533533                admin_url( 'theme-editor.php' )
     
    536536            $url = admin_url();
    537537        }
    538         $url = add_query_arg( $scrape_params, $url );
    539         $r = wp_remote_get( $url, compact( 'cookies', 'headers', 'timeout' ) );
    540         $body = wp_remote_retrieve_body( $r );
     538        $url                    = add_query_arg( $scrape_params, $url );
     539        $r                      = wp_remote_get( $url, compact( 'cookies', 'headers', 'timeout' ) );
     540        $body                   = wp_remote_retrieve_body( $r );
    541541        $scrape_result_position = strpos( $body, $needle_start );
    542542
    543543        $loopback_request_failure = array(
    544             'code' => 'loopback_request_failed',
     544            'code'    => 'loopback_request_failed',
    545545            'message' => __( 'Unable to communicate back with site to check for fatal errors, so the PHP change was reverted. You will need to upload your PHP file change by some other means, such as by using SFTP.' ),
    546546        );
    547         $json_parse_failure = array(
     547        $json_parse_failure       = array(
    548548            'code' => 'json_parse_error',
    549549        );
     
    555555            $error_output = substr( $body, $scrape_result_position + strlen( $needle_start ) );
    556556            $error_output = substr( $error_output, 0, strpos( $error_output, $needle_end ) );
    557             $result = json_decode( trim( $error_output ), true );
     557            $result       = json_decode( trim( $error_output ), true );
    558558            if ( empty( $result ) ) {
    559559                $result = $json_parse_failure;
     
    563563        // Try making request to homepage as well to see if visitors have been whitescreened.
    564564        if ( true === $result ) {
    565             $url = home_url( '/' );
    566             $url = add_query_arg( $scrape_params, $url );
    567             $r = wp_remote_get( $url, compact( 'cookies', 'headers', 'timeout' ) );
    568             $body = wp_remote_retrieve_body( $r );
     565            $url                    = home_url( '/' );
     566            $url                    = add_query_arg( $scrape_params, $url );
     567            $r                      = wp_remote_get( $url, compact( 'cookies', 'headers', 'timeout' ) );
     568            $body                   = wp_remote_retrieve_body( $r );
    569569            $scrape_result_position = strpos( $body, $needle_start );
    570570
     
    574574                $error_output = substr( $body, $scrape_result_position + strlen( $needle_start ) );
    575575                $error_output = substr( $error_output, 0, strpos( $error_output, $needle_end ) );
    576                 $result = json_decode( trim( $error_output ), true );
     576                $result       = json_decode( trim( $error_output ), true );
    577577                if ( empty( $result ) ) {
    578578                    $result = $json_parse_failure;
     
    643643    $temp_filename .= '-' . wp_generate_password( 6, false );
    644644    $temp_filename .= '.tmp';
    645     $temp_filename = $dir . wp_unique_filename( $dir, $temp_filename );
     645    $temp_filename  = $dir . wp_unique_filename( $dir, $temp_filename );
    646646
    647647    $fp = @fopen( $temp_filename, 'x' );
     
    670670    $code = validate_file( $file, $allowed_files );
    671671
    672     if (!$code )
     672    if ( ! $code ) {
    673673        return $file;
     674    }
    674675
    675676    switch ( $code ) {
    676         case 1 :
     677        case 1:
    677678            wp_die( __( 'Sorry, that file cannot be edited.' ) );
    678679
    679         // case 2 :
    680         // wp_die( __('Sorry, can’t call files with their real path.' ));
    681 
    682         case 3 :
     680            // case 2 :
     681            // wp_die( __('Sorry, can’t call files with their real path.' ));
     682
     683        case 3:
    683684            wp_die( __( 'Sorry, that file cannot be edited.' ) );
    684685    }
     
    757758            __( 'Missing a temporary folder.' ),
    758759            __( 'Failed to write file to disk.' ),
    759             __( 'File upload stopped by extension.' )
     760            __( 'File upload stopped by extension.' ),
    760761        );
    761762    }
     
    767768    // If you override this, you must provide $ext and $type!!
    768769    $test_type = isset( $overrides['test_type'] ) ? $overrides['test_type'] : true;
    769     $mimes = isset( $overrides['mimes'] ) ? $overrides['mimes'] : false;
     770    $mimes     = isset( $overrides['mimes'] ) ? $overrides['mimes'] : false;
    770771
    771772    // A correct form post will pass this test.
     
    797798    // A correct MIME type will pass this test. Override $mimes or use the upload_mimes filter.
    798799    if ( $test_type ) {
    799         $wp_filetype = wp_check_filetype_and_ext( $file['tmp_name'], $file['name'], $mimes );
    800         $ext = empty( $wp_filetype['ext'] ) ? '' : $wp_filetype['ext'];
    801         $type = empty( $wp_filetype['type'] ) ? '' : $wp_filetype['type'];
     800        $wp_filetype     = wp_check_filetype_and_ext( $file['tmp_name'], $file['name'], $mimes );
     801        $ext             = empty( $wp_filetype['ext'] ) ? '' : $wp_filetype['ext'];
     802        $type            = empty( $wp_filetype['type'] ) ? '' : $wp_filetype['type'];
    802803        $proper_filename = empty( $wp_filetype['proper_filename'] ) ? '' : $wp_filetype['proper_filename'];
    803804
     
    806807            $file['name'] = $proper_filename;
    807808        }
    808         if ( ( ! $type || !$ext ) && ! current_user_can( 'unfiltered_upload' ) ) {
     809        if ( ( ! $type || ! $ext ) && ! current_user_can( 'unfiltered_upload' ) ) {
    809810            return call_user_func_array( $upload_error_handler, array( &$file, __( 'Sorry, this file type is not permitted for security reasons.' ) ) );
    810811        }
     
    829830    $new_file = $uploads['path'] . "/$filename";
    830831
    831     /**
     832    /**
    832833     * Filters whether to short-circuit moving the uploaded file after passing all checks.
    833834     *
     
    859860                $error_path = basename( $uploads['basedir'] ) . $uploads['subdir'];
    860861            }
    861             return $upload_error_handler( $file, sprintf( __('The uploaded file could not be moved to %s.' ), $error_path ) );
     862            return $upload_error_handler( $file, sprintf( __( 'The uploaded file could not be moved to %s.' ), $error_path ) );
    862863        }
    863864    }
    864865
    865866    // Set correct file permissions.
    866     $stat = stat( dirname( $new_file ));
     867    $stat  = stat( dirname( $new_file ) );
    867868    $perms = $stat['mode'] & 0000666;
    868869    @ chmod( $new_file, $perms );
     
    889890     * @param string $context The type of upload action. Values include 'upload' or 'sideload'.
    890891     */
    891     return apply_filters( 'wp_handle_upload', array(
    892         'file' => $new_file,
    893         'url'  => $url,
    894         'type' => $type
    895     ), 'wp_handle_sideload' === $action ? 'sideload' : 'upload' );
     892    return apply_filters(
     893        'wp_handle_upload', array(
     894            'file' => $new_file,
     895            'url'  => $url,
     896            'type' => $type,
     897        ), 'wp_handle_sideload' === $action ? 'sideload' : 'upload'
     898    );
    896899}
    897900
     
    967970function download_url( $url, $timeout = 300 ) {
    968971    //WARNING: The file is not automatically deleted, The script must unlink() the file.
    969     if ( ! $url )
    970         return new WP_Error('http_no_url', __('Invalid URL Provided.'));
     972    if ( ! $url ) {
     973        return new WP_Error( 'http_no_url', __( 'Invalid URL Provided.' ) );
     974    }
    971975
    972976    $url_filename = basename( parse_url( $url, PHP_URL_PATH ) );
    973977
    974978    $tmpfname = wp_tempnam( $url_filename );
    975     if ( ! $tmpfname )
    976         return new WP_Error('http_no_file', __('Could not create Temporary file.'));
    977 
    978     $response = wp_safe_remote_get( $url, array( 'timeout' => $timeout, 'stream' => true, 'filename' => $tmpfname ) );
     979    if ( ! $tmpfname ) {
     980        return new WP_Error( 'http_no_file', __( 'Could not create Temporary file.' ) );
     981    }
     982
     983    $response = wp_safe_remote_get(
     984        $url, array(
     985            'timeout'  => $timeout,
     986            'stream'   => true,
     987            'filename' => $tmpfname,
     988        )
     989    );
    979990
    980991    if ( is_wp_error( $response ) ) {
     
    983994    }
    984995
    985     if ( 200 != wp_remote_retrieve_response_code( $response ) ){
     996    if ( 200 != wp_remote_retrieve_response_code( $response ) ) {
    986997        unlink( $tmpfname );
    987998        return new WP_Error( 'http_404', trim( wp_remote_retrieve_response_message( $response ) ) );
     
    10101021 */
    10111022function verify_file_md5( $filename, $expected_md5 ) {
    1012     if ( 32 == strlen( $expected_md5 ) )
     1023    if ( 32 == strlen( $expected_md5 ) ) {
    10131024        $expected_raw_md5 = pack( 'H*', $expected_md5 );
    1014     elseif ( 24 == strlen( $expected_md5 ) )
     1025    } elseif ( 24 == strlen( $expected_md5 ) ) {
    10151026        $expected_raw_md5 = base64_decode( $expected_md5 );
    1016     else
     1027    } else {
    10171028        return false; // unknown format
     1029    }
    10181030
    10191031    $file_md5 = md5_file( $filename, true );
    10201032
    1021     if ( $file_md5 === $expected_raw_md5 )
     1033    if ( $file_md5 === $expected_raw_md5 ) {
    10221034        return true;
     1035    }
    10231036
    10241037    return new WP_Error( 'md5_mismatch', sprintf( __( 'The checksum of the file (%1$s) does not match the expected checksum value (%2$s).' ), bin2hex( $file_md5 ), bin2hex( $expected_raw_md5 ) ) );
     
    10401053 * @return mixed WP_Error on failure, True on success
    10411054 */
    1042 function unzip_file($file, $to) {
     1055function unzip_file( $file, $to ) {
    10431056    global $wp_filesystem;
    10441057
    1045     if ( ! $wp_filesystem || !is_object($wp_filesystem) )
    1046         return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
     1058    if ( ! $wp_filesystem || ! is_object( $wp_filesystem ) ) {
     1059        return new WP_Error( 'fs_unavailable', __( 'Could not access filesystem.' ) );
     1060    }
    10471061
    10481062    // Unzip can use a lot of memory, but not this much hopefully.
     
    10501064
    10511065    $needed_dirs = array();
    1052     $to = trailingslashit($to);
     1066    $to          = trailingslashit( $to );
    10531067
    10541068    // Determine any parent dir's needed (of the upgrade directory)
    1055     if ( ! $wp_filesystem->is_dir($to) ) { //Only do parents if no children exist
    1056         $path = preg_split('![/\\\]!', untrailingslashit($to));
    1057         for ( $i = count($path); $i >= 0; $i-- ) {
    1058             if ( empty($path[$i]) )
     1069    if ( ! $wp_filesystem->is_dir( $to ) ) { //Only do parents if no children exist
     1070        $path = preg_split( '![/\\\]!', untrailingslashit( $to ) );
     1071        for ( $i = count( $path ); $i >= 0; $i-- ) {
     1072            if ( empty( $path[ $i ] ) ) {
    10591073                continue;
    1060 
    1061             $dir = implode('/', array_slice($path, 0, $i+1) );
    1062             if ( preg_match('!^[a-z]:$!i', $dir) ) // Skip it if it looks like a Windows Drive letter.
     1074            }
     1075
     1076            $dir = implode( '/', array_slice( $path, 0, $i + 1 ) );
     1077            if ( preg_match( '!^[a-z]:$!i', $dir ) ) { // Skip it if it looks like a Windows Drive letter.
    10631078                continue;
    1064 
    1065             if ( ! $wp_filesystem->is_dir($dir) )
     1079            }
     1080
     1081            if ( ! $wp_filesystem->is_dir( $dir ) ) {
    10661082                $needed_dirs[] = $dir;
    1067             else
     1083            } else {
    10681084                break; // A folder exists, therefor, we dont need the check the levels below this
     1085            }
    10691086        }
    10701087    }
     
    10781095     */
    10791096    if ( class_exists( 'ZipArchive', false ) && apply_filters( 'unzip_file_use_ziparchive', true ) ) {
    1080         $result = _unzip_file_ziparchive($file, $to, $needed_dirs);
     1097        $result = _unzip_file_ziparchive( $file, $to, $needed_dirs );
    10811098        if ( true === $result ) {
    10821099            return $result;
    1083         } elseif ( is_wp_error($result) ) {
    1084             if ( 'incompatible_archive' != $result->get_error_code() )
     1100        } elseif ( is_wp_error( $result ) ) {
     1101            if ( 'incompatible_archive' != $result->get_error_code() ) {
    10851102                return $result;
     1103            }
    10861104        }
    10871105    }
    10881106    // Fall through to PclZip if ZipArchive is not available, or encountered an error opening the file.
    1089     return _unzip_file_pclzip($file, $to, $needed_dirs);
     1107    return _unzip_file_pclzip( $file, $to, $needed_dirs );
    10901108}
    10911109
     
    11051123 * @return mixed WP_Error on failure, True on success
    11061124 */
    1107 function _unzip_file_ziparchive($file, $to, $needed_dirs = array() ) {
     1125function _unzip_file_ziparchive( $file, $to, $needed_dirs = array() ) {
    11081126    global $wp_filesystem;
    11091127
     
    11111129
    11121130    $zopen = $z->open( $file, ZIPARCHIVE::CHECKCONS );
    1113     if ( true !== $zopen )
     1131    if ( true !== $zopen ) {
    11141132        return new WP_Error( 'incompatible_archive', __( 'Incompatible Archive.' ), array( 'ziparchive_error' => $zopen ) );
     1133    }
    11151134
    11161135    $uncompressed_size = 0;
    11171136
    11181137    for ( $i = 0; $i < $z->numFiles; $i++ ) {
    1119         if ( ! $info = $z->statIndex($i) )
     1138        if ( ! $info = $z->statIndex( $i ) ) {
    11201139            return new WP_Error( 'stat_failed_ziparchive', __( 'Could not retrieve file from archive.' ) );
    1121 
    1122         if ( '__MACOSX/' === substr($info['name'], 0, 9) ) // Skip the OS X-created __MACOSX directory
     1140        }
     1141
     1142        if ( '__MACOSX/' === substr( $info['name'], 0, 9 ) ) { // Skip the OS X-created __MACOSX directory
    11231143            continue;
     1144        }
    11241145
    11251146        // Don't extract invalid files:
     
    11461167    if ( wp_doing_cron() ) {
    11471168        $available_space = @disk_free_space( WP_CONTENT_DIR );
    1148         if ( $available_space && ( $uncompressed_size * 2.1 ) > $available_space )
     1169        if ( $available_space && ( $uncompressed_size * 2.1 ) > $available_space ) {
    11491170            return new WP_Error( 'disk_full_unzip_file', __( 'Could not copy files. You may have run out of disk space.' ), compact( 'uncompressed_size', 'available_space' ) );
    1150     }
    1151 
    1152     $needed_dirs = array_unique($needed_dirs);
     1171        }
     1172    }
     1173
     1174    $needed_dirs = array_unique( $needed_dirs );
    11531175    foreach ( $needed_dirs as $dir ) {
    11541176        // Check the parent folders of the folders all exist within the creation array.
    1155         if ( untrailingslashit($to) == $dir ) // Skip over the working directory, We know this exists (or will exist)
     1177        if ( untrailingslashit( $to ) == $dir ) { // Skip over the working directory, We know this exists (or will exist)
    11561178            continue;
    1157         if ( strpos($dir, $to) === false ) // If the directory is not within the working directory, Skip it
     1179        }
     1180        if ( strpos( $dir, $to ) === false ) { // If the directory is not within the working directory, Skip it
    11581181            continue;
    1159 
    1160         $parent_folder = dirname($dir);
    1161         while ( !empty($parent_folder) && untrailingslashit($to) != $parent_folder && !in_array($parent_folder, $needed_dirs) ) {
     1182        }
     1183
     1184        $parent_folder = dirname( $dir );
     1185        while ( ! empty( $parent_folder ) && untrailingslashit( $to ) != $parent_folder && ! in_array( $parent_folder, $needed_dirs ) ) {
    11621186            $needed_dirs[] = $parent_folder;
    1163             $parent_folder = dirname($parent_folder);
    1164         }
    1165     }
    1166     asort($needed_dirs);
     1187            $parent_folder = dirname( $parent_folder );
     1188        }
     1189    }
     1190    asort( $needed_dirs );
    11671191
    11681192    // Create those directories if need be:
     
    11731197        }
    11741198    }
    1175     unset($needed_dirs);
     1199    unset( $needed_dirs );
    11761200
    11771201    for ( $i = 0; $i < $z->numFiles; $i++ ) {
    1178         if ( ! $info = $z->statIndex($i) )
     1202        if ( ! $info = $z->statIndex( $i ) ) {
    11791203            return new WP_Error( 'stat_failed_ziparchive', __( 'Could not retrieve file from archive.' ) );
    1180 
    1181         if ( '/' == substr($info['name'], -1) ) // directory
     1204        }
     1205
     1206        if ( '/' == substr( $info['name'], -1 ) ) { // directory
    11821207            continue;
    1183 
    1184         if ( '__MACOSX/' === substr($info['name'], 0, 9) ) // Don't extract the OS X-created __MACOSX directory files
     1208        }
     1209
     1210        if ( '__MACOSX/' === substr( $info['name'], 0, 9 ) ) { // Don't extract the OS X-created __MACOSX directory files
    11851211            continue;
     1212        }
    11861213
    11871214        // Don't extract invalid files:
     
    11901217        }
    11911218
    1192         $contents = $z->getFromIndex($i);
    1193         if ( false === $contents )
     1219        $contents = $z->getFromIndex( $i );
     1220        if ( false === $contents ) {
    11941221            return new WP_Error( 'extract_failed_ziparchive', __( 'Could not extract file from archive.' ), $info['name'] );
    1195 
    1196         if ( ! $wp_filesystem->put_contents( $to . $info['name'], $contents, FS_CHMOD_FILE) )
     1222        }
     1223
     1224        if ( ! $wp_filesystem->put_contents( $to . $info['name'], $contents, FS_CHMOD_FILE ) ) {
    11971225            return new WP_Error( 'copy_failed_ziparchive', __( 'Could not copy file.' ), $info['name'] );
     1226        }
    11981227    }
    11991228
     
    12181247 * @return mixed WP_Error on failure, True on success
    12191248 */
    1220 function _unzip_file_pclzip($file, $to, $needed_dirs = array()) {
     1249function _unzip_file_pclzip( $file, $to, $needed_dirs = array() ) {
    12211250    global $wp_filesystem;
    12221251
    12231252    mbstring_binary_safe_encoding();
    12241253
    1225     require_once(ABSPATH . 'wp-admin/includes/class-pclzip.php');
    1226 
    1227     $archive = new PclZip($file);
    1228 
    1229     $archive_files = $archive->extract(PCLZIP_OPT_EXTRACT_AS_STRING);
     1254    require_once( ABSPATH . 'wp-admin/includes/class-pclzip.php' );
     1255
     1256    $archive = new PclZip( $file );
     1257
     1258    $archive_files = $archive->extract( PCLZIP_OPT_EXTRACT_AS_STRING );
    12301259
    12311260    reset_mbstring_encoding();
    12321261
    12331262    // Is the archive valid?
    1234     if ( !is_array($archive_files) )
    1235         return new WP_Error('incompatible_archive', __('Incompatible Archive.'), $archive->errorInfo(true));
    1236 
    1237     if ( 0 == count($archive_files) )
     1263    if ( ! is_array( $archive_files ) ) {
     1264        return new WP_Error( 'incompatible_archive', __( 'Incompatible Archive.' ), $archive->errorInfo( true ) );
     1265    }
     1266
     1267    if ( 0 == count( $archive_files ) ) {
    12381268        return new WP_Error( 'empty_archive_pclzip', __( 'Empty archive.' ) );
     1269    }
    12391270
    12401271    $uncompressed_size = 0;
     
    12421273    // Determine any children directories needed (From within the archive)
    12431274    foreach ( $archive_files as $file ) {
    1244         if ( '__MACOSX/' === substr($file['filename'], 0, 9) ) // Skip the OS X-created __MACOSX directory
     1275        if ( '__MACOSX/' === substr( $file['filename'], 0, 9 ) ) { // Skip the OS X-created __MACOSX directory
    12451276            continue;
     1277        }
    12461278
    12471279        $uncompressed_size += $file['size'];
    12481280
    1249         $needed_dirs[] = $to . untrailingslashit( $file['folder'] ? $file['filename'] : dirname($file['filename']) );
     1281        $needed_dirs[] = $to . untrailingslashit( $file['folder'] ? $file['filename'] : dirname( $file['filename'] ) );
    12501282    }
    12511283
     
    12571289    if ( wp_doing_cron() ) {
    12581290        $available_space = @disk_free_space( WP_CONTENT_DIR );
    1259         if ( $available_space && ( $uncompressed_size * 2.1 ) > $available_space )
     1291        if ( $available_space && ( $uncompressed_size * 2.1 ) > $available_space ) {
    12601292            return new WP_Error( 'disk_full_unzip_file', __( 'Could not copy files. You may have run out of disk space.' ), compact( 'uncompressed_size', 'available_space' ) );
    1261     }
    1262 
    1263     $needed_dirs = array_unique($needed_dirs);
     1293        }
     1294    }
     1295
     1296    $needed_dirs = array_unique( $needed_dirs );
    12641297    foreach ( $needed_dirs as $dir ) {
    12651298        // Check the parent folders of the folders all exist within the creation array.
    1266         if ( untrailingslashit($to) == $dir ) // Skip over the working directory, We know this exists (or will exist)
     1299        if ( untrailingslashit( $to ) == $dir ) { // Skip over the working directory, We know this exists (or will exist)
    12671300            continue;
    1268         if ( strpos($dir, $to) === false ) // If the directory is not within the working directory, Skip it
     1301        }
     1302        if ( strpos( $dir, $to ) === false ) { // If the directory is not within the working directory, Skip it
    12691303            continue;
    1270 
    1271         $parent_folder = dirname($dir);
    1272         while ( !empty($parent_folder) && untrailingslashit($to) != $parent_folder && !in_array($parent_folder, $needed_dirs) ) {
     1304        }
     1305
     1306        $parent_folder = dirname( $dir );
     1307        while ( ! empty( $parent_folder ) && untrailingslashit( $to ) != $parent_folder && ! in_array( $parent_folder, $needed_dirs ) ) {
    12731308            $needed_dirs[] = $parent_folder;
    1274             $parent_folder = dirname($parent_folder);
    1275         }
    1276     }
    1277     asort($needed_dirs);
     1309            $parent_folder = dirname( $parent_folder );
     1310        }
     1311    }
     1312    asort( $needed_dirs );
    12781313
    12791314    // Create those directories if need be:
    12801315    foreach ( $needed_dirs as $_dir ) {
    12811316        // Only check to see if the dir exists upon creation failure. Less I/O this way.
    1282         if ( ! $wp_filesystem->mkdir( $_dir, FS_CHMOD_DIR ) && ! $wp_filesystem->is_dir( $_dir ) )
     1317        if ( ! $wp_filesystem->mkdir( $_dir, FS_CHMOD_DIR ) && ! $wp_filesystem->is_dir( $_dir ) ) {
    12831318            return new WP_Error( 'mkdir_failed_pclzip', __( 'Could not create directory.' ), substr( $_dir, strlen( $to ) ) );
    1284     }
    1285     unset($needed_dirs);
     1319        }
     1320    }
     1321    unset( $needed_dirs );
    12861322
    12871323    // Extract the files from the zip
    12881324    foreach ( $archive_files as $file ) {
    1289         if ( $file['folder'] )
     1325        if ( $file['folder'] ) {
    12901326            continue;
    1291 
    1292         if ( '__MACOSX/' === substr($file['filename'], 0, 9) ) // Don't extract the OS X-created __MACOSX directory files
     1327        }
     1328
     1329        if ( '__MACOSX/' === substr( $file['filename'], 0, 9 ) ) { // Don't extract the OS X-created __MACOSX directory files
    12931330            continue;
     1331        }
    12941332
    12951333        // Don't extract invalid files:
     
    12981336        }
    12991337
    1300         if ( ! $wp_filesystem->put_contents( $to . $file['filename'], $file['content'], FS_CHMOD_FILE) )
     1338        if ( ! $wp_filesystem->put_contents( $to . $file['filename'], $file['content'], FS_CHMOD_FILE ) ) {
    13011339            return new WP_Error( 'copy_failed_pclzip', __( 'Could not copy file.' ), $file['filename'] );
     1340        }
    13021341    }
    13031342    return true;
     
    13171356 * @return mixed WP_Error on failure, True on success.
    13181357 */
    1319 function copy_dir($from, $to, $skip_list = array() ) {
     1358function copy_dir( $from, $to, $skip_list = array() ) {
    13201359    global $wp_filesystem;
    13211360
    1322     $dirlist = $wp_filesystem->dirlist($from);
    1323 
    1324     $from = trailingslashit($from);
    1325     $to = trailingslashit($to);
     1361    $dirlist = $wp_filesystem->dirlist( $from );
     1362
     1363    $from = trailingslashit( $from );
     1364    $to   = trailingslashit( $to );
    13261365
    13271366    foreach ( (array) $dirlist as $filename => $fileinfo ) {
    1328         if ( in_array( $filename, $skip_list ) )
     1367        if ( in_array( $filename, $skip_list ) ) {
    13291368            continue;
     1369        }
    13301370
    13311371        if ( 'f' == $fileinfo['type'] ) {
    1332             if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) ) {
     1372            if ( ! $wp_filesystem->copy( $from . $filename, $to . $filename, true, FS_CHMOD_FILE ) ) {
    13331373                // If copy failed, chmod file to 0644 and try again.
    13341374                $wp_filesystem->chmod( $to . $filename, FS_CHMOD_FILE );
    1335                 if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) )
     1375                if ( ! $wp_filesystem->copy( $from . $filename, $to . $filename, true, FS_CHMOD_FILE ) ) {
    13361376                    return new WP_Error( 'copy_failed_copy_dir', __( 'Could not copy file.' ), $to . $filename );
     1377                }
    13371378            }
    13381379        } elseif ( 'd' == $fileinfo['type'] ) {
    1339             if ( !$wp_filesystem->is_dir($to . $filename) ) {
    1340                 if ( !$wp_filesystem->mkdir($to . $filename, FS_CHMOD_DIR) )
     1380            if ( ! $wp_filesystem->is_dir( $to . $filename ) ) {
     1381                if ( ! $wp_filesystem->mkdir( $to . $filename, FS_CHMOD_DIR ) ) {
    13411382                    return new WP_Error( 'mkdir_failed_copy_dir', __( 'Could not create directory.' ), $to . $filename );
     1383                }
    13421384            }
    13431385
     
    13451387            $sub_skip_list = array();
    13461388            foreach ( $skip_list as $skip_item ) {
    1347                 if ( 0 === strpos( $skip_item, $filename . '/' ) )
     1389                if ( 0 === strpos( $skip_item, $filename . '/' ) ) {
    13481390                    $sub_skip_list[] = preg_replace( '!^' . preg_quote( $filename, '!' ) . '/!i', '', $skip_item );
     1391                }
    13491392            }
    13501393
    1351             $result = copy_dir($from . $filename, $to . $filename, $sub_skip_list);
    1352             if ( is_wp_error($result) )
     1394            $result = copy_dir( $from . $filename, $to . $filename, $sub_skip_list );
     1395            if ( is_wp_error( $result ) ) {
    13531396                return $result;
     1397            }
    13541398        }
    13551399    }
     
    13771421    global $wp_filesystem;
    13781422
    1379     require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php');
     1423    require_once( ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php' );
    13801424
    13811425    $method = get_filesystem_method( $args, $context, $allow_relaxed_file_ownership );
    13821426
    1383     if ( ! $method )
     1427    if ( ! $method ) {
    13841428        return false;
     1429    }
    13851430
    13861431    if ( ! class_exists( "WP_Filesystem_$method" ) ) {
     
    13981443        $abstraction_file = apply_filters( 'filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method );
    13991444
    1400         if ( ! file_exists($abstraction_file) )
     1445        if ( ! file_exists( $abstraction_file ) ) {
    14011446            return;
    1402 
    1403         require_once($abstraction_file);
     1447        }
     1448
     1449        require_once( $abstraction_file );
    14041450    }
    14051451    $method = "WP_Filesystem_$method";
    14061452
    1407     $wp_filesystem = new $method($args);
     1453    $wp_filesystem = new $method( $args );
    14081454
    14091455    //Define the timeouts for the connections. Only available after the construct is called to allow for per-transport overriding of the default.
    1410     if ( ! defined('FS_CONNECT_TIMEOUT') )
    1411         define('FS_CONNECT_TIMEOUT', 30);
    1412     if ( ! defined('FS_TIMEOUT') )
    1413         define('FS_TIMEOUT', 30);
    1414 
    1415     if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() )
     1456    if ( ! defined( 'FS_CONNECT_TIMEOUT' ) ) {
     1457        define( 'FS_CONNECT_TIMEOUT', 30 );
     1458    }
     1459    if ( ! defined( 'FS_TIMEOUT' ) ) {
     1460        define( 'FS_TIMEOUT', 30 );
     1461    }
     1462
     1463    if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) {
    14161464        return false;
    1417 
    1418     if ( !$wp_filesystem->connect() )
     1465    }
     1466
     1467    if ( ! $wp_filesystem->connect() ) {
    14191468        return false; //There was an error connecting to the server.
     1469    }
    14201470
    14211471    // Set the permission constants if not already set.
    1422     if ( ! defined('FS_CHMOD_DIR') )
    1423         define('FS_CHMOD_DIR', ( fileperms( ABSPATH ) & 0777 | 0755 ) );
    1424     if ( ! defined('FS_CHMOD_FILE') )
    1425         define('FS_CHMOD_FILE', ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 ) );
     1472    if ( ! defined( 'FS_CHMOD_DIR' ) ) {
     1473        define( 'FS_CHMOD_DIR', ( fileperms( ABSPATH ) & 0777 | 0755 ) );
     1474    }
     1475    if ( ! defined( 'FS_CHMOD_FILE' ) ) {
     1476        define( 'FS_CHMOD_FILE', ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 ) );
     1477    }
    14261478
    14271479    return true;
     
    14551507 */
    14561508function get_filesystem_method( $args = array(), $context = '', $allow_relaxed_file_ownership = false ) {
    1457     $method = defined('FS_METHOD') ? FS_METHOD : false; // Please ensure that this is either 'direct', 'ssh2', 'ftpext' or 'ftpsockets'
     1509    $method = defined( 'FS_METHOD' ) ? FS_METHOD : false; // Please ensure that this is either 'direct', 'ssh2', 'ftpext' or 'ftpsockets'
    14581510
    14591511    if ( ! $context ) {
     
    14711523
    14721524        $temp_file_name = $context . 'temp-write-test-' . str_replace( '.', '-', uniqid( '', true ) );
    1473         $temp_handle = @fopen($temp_file_name, 'w');
     1525        $temp_handle    = @fopen( $temp_file_name, 'w' );
    14741526        if ( $temp_handle ) {
    14751527
    14761528            // Attempt to determine the file owner of the WordPress files, and that of newly created files
    14771529            $wp_file_owner = $temp_file_owner = false;
    1478             if ( function_exists('fileowner') ) {
    1479                 $wp_file_owner = @fileowner( __FILE__ );
     1530            if ( function_exists( 'fileowner' ) ) {
     1531                $wp_file_owner   = @fileowner( __FILE__ );
    14801532                $temp_file_owner = @fileowner( $temp_file_name );
    14811533            }
     
    14841536                // WordPress is creating files as the same owner as the WordPress files,
    14851537                // this means it's safe to modify & create new files via PHP.
    1486                 $method = 'direct';
     1538                $method                                  = 'direct';
    14871539                $GLOBALS['_wp_filesystem_direct_method'] = 'file_owner';
    14881540            } elseif ( $allow_relaxed_file_ownership ) {
    14891541                // The $context directory is writable, and $allow_relaxed_file_ownership is set, this means we can modify files
    14901542                // safely in this directory. This mode doesn't create new files, only alter existing ones.
    1491                 $method = 'direct';
     1543                $method                                  = 'direct';
    14921544                $GLOBALS['_wp_filesystem_direct_method'] = 'relaxed_ownership';
    14931545            }
    14941546
    1495             @fclose($temp_handle);
    1496             @unlink($temp_file_name);
    1497         }
    1498     }
    1499 
    1500     if ( ! $method && isset($args['connection_type']) && 'ssh' == $args['connection_type'] && extension_loaded('ssh2') && function_exists('stream_get_contents') ) $method = 'ssh2';
    1501     if ( ! $method && extension_loaded('ftp') ) $method = 'ftpext';
    1502     if ( ! $method && ( extension_loaded('sockets') || function_exists('fsockopen') ) ) $method = 'ftpsockets'; //Sockets: Socket extension; PHP Mode: FSockopen / fwrite / fread
     1547            @fclose( $temp_handle );
     1548            @unlink( $temp_file_name );
     1549        }
     1550    }
     1551
     1552    if ( ! $method && isset( $args['connection_type'] ) && 'ssh' == $args['connection_type'] && extension_loaded( 'ssh2' ) && function_exists( 'stream_get_contents' ) ) {
     1553        $method = 'ssh2';
     1554    }
     1555    if ( ! $method && extension_loaded( 'ftp' ) ) {
     1556        $method = 'ftpext';
     1557    }
     1558    if ( ! $method && ( extension_loaded( 'sockets' ) || function_exists( 'fsockopen' ) ) ) {
     1559        $method = 'ftpsockets'; //Sockets: Socket extension; PHP Mode: FSockopen / fwrite / fread
     1560    }
    15031561
    15041562    /**
     
    15671625     */
    15681626    $req_cred = apply_filters( 'request_filesystem_credentials', '', $form_post, $type, $error, $context, $extra_fields, $allow_relaxed_file_ownership );
    1569     if ( '' !== $req_cred )
     1627    if ( '' !== $req_cred ) {
    15701628        return $req_cred;
    1571 
    1572     if ( empty($type) ) {
     1629    }
     1630
     1631    if ( empty( $type ) ) {
    15731632        $type = get_filesystem_method( array(), $context, $allow_relaxed_file_ownership );
    15741633    }
    15751634
    1576     if ( 'direct' == $type )
     1635    if ( 'direct' == $type ) {
    15771636        return true;
    1578 
    1579     if ( is_null( $extra_fields ) )
     1637    }
     1638
     1639    if ( is_null( $extra_fields ) ) {
    15801640        $extra_fields = array( 'version', 'locale' );
    1581 
    1582     $credentials = get_option('ftp_credentials', array( 'hostname' => '', 'username' => ''));
     1641    }
     1642
     1643    $credentials = get_option(
     1644        'ftp_credentials', array(
     1645            'hostname' => '',
     1646            'username' => '',
     1647        )
     1648    );
    15831649
    15841650    $submitted_form = wp_unslash( $_POST );
     
    15971663
    15981664    // If defined, set it to that, Else, If POST'd, set it to that, If not, Set it to whatever it previously was(saved details in option)
    1599     $credentials['hostname'] = defined('FTP_HOST') ? FTP_HOST : (!empty($submitted_form['hostname']) ? $submitted_form['hostname'] : $credentials['hostname']);
    1600     $credentials['username'] = defined('FTP_USER') ? FTP_USER : (!empty($submitted_form['username']) ? $submitted_form['username'] : $credentials['username']);
    1601     $credentials['password'] = defined('FTP_PASS') ? FTP_PASS : (!empty($submitted_form['password']) ? $submitted_form['password'] : '');
     1665    $credentials['hostname'] = defined( 'FTP_HOST' ) ? FTP_HOST : ( ! empty( $submitted_form['hostname'] ) ? $submitted_form['hostname'] : $credentials['hostname'] );
     1666    $credentials['username'] = defined( 'FTP_USER' ) ? FTP_USER : ( ! empty( $submitted_form['username'] ) ? $submitted_form['username'] : $credentials['username'] );
     1667    $credentials['password'] = defined( 'FTP_PASS' ) ? FTP_PASS : ( ! empty( $submitted_form['password'] ) ? $submitted_form['password'] : '' );
    16021668
    16031669    // Check to see if we are setting the public/private keys for ssh
    1604     $credentials['public_key'] = defined('FTP_PUBKEY') ? FTP_PUBKEY : (!empty($submitted_form['public_key']) ? $submitted_form['public_key'] : '');
    1605     $credentials['private_key'] = defined('FTP_PRIKEY') ? FTP_PRIKEY : (!empty($submitted_form['private_key']) ? $submitted_form['private_key'] : '');
     1670    $credentials['public_key']  = defined( 'FTP_PUBKEY' ) ? FTP_PUBKEY : ( ! empty( $submitted_form['public_key'] ) ? $submitted_form['public_key'] : '' );
     1671    $credentials['private_key'] = defined( 'FTP_PRIKEY' ) ? FTP_PRIKEY : ( ! empty( $submitted_form['private_key'] ) ? $submitted_form['private_key'] : '' );
    16061672
    16071673    // Sanitize the hostname, Some people might pass in odd-data:
    1608     $credentials['hostname'] = preg_replace('|\w+://|', '', $credentials['hostname']); //Strip any schemes off
    1609 
    1610     if ( strpos($credentials['hostname'], ':') ) {
    1611         list( $credentials['hostname'], $credentials['port'] ) = explode(':', $credentials['hostname'], 2);
    1612         if ( ! is_numeric($credentials['port']) )
    1613             unset($credentials['port']);
     1674    $credentials['hostname'] = preg_replace( '|\w+://|', '', $credentials['hostname'] ); //Strip any schemes off
     1675
     1676    if ( strpos( $credentials['hostname'], ':' ) ) {
     1677        list( $credentials['hostname'], $credentials['port'] ) = explode( ':', $credentials['hostname'], 2 );
     1678        if ( ! is_numeric( $credentials['port'] ) ) {
     1679            unset( $credentials['port'] );
     1680        }
    16141681    } else {
    1615         unset($credentials['port']);
     1682        unset( $credentials['port'] );
    16161683    }
    16171684
     
    16271694    if ( ! $error &&
    16281695            (
    1629                 ( !empty($credentials['password']) && !empty($credentials['username']) && !empty($credentials['hostname']) ) ||
    1630                 ( 'ssh' == $credentials['connection_type'] && !empty($credentials['public_key']) && !empty($credentials['private_key']) )
     1696                ( ! empty( $credentials['password'] ) && ! empty( $credentials['username'] ) && ! empty( $credentials['hostname'] ) ) ||
     1697                ( 'ssh' == $credentials['connection_type'] && ! empty( $credentials['public_key'] ) && ! empty( $credentials['private_key'] ) )
    16311698            ) ) {
    16321699        $stored_credentials = $credentials;
    1633         if ( !empty($stored_credentials['port']) ) //save port as part of hostname to simplify above code.
     1700        if ( ! empty( $stored_credentials['port'] ) ) { //save port as part of hostname to simplify above code.
    16341701            $stored_credentials['hostname'] .= ':' . $stored_credentials['port'];
    1635 
    1636         unset($stored_credentials['password'], $stored_credentials['port'], $stored_credentials['private_key'], $stored_credentials['public_key']);
     1702        }
     1703
     1704        unset( $stored_credentials['password'], $stored_credentials['port'], $stored_credentials['private_key'], $stored_credentials['public_key'] );
    16371705        if ( ! wp_installing() ) {
    16381706            update_option( 'ftp_credentials', $stored_credentials );
     
    16401708        return $credentials;
    16411709    }
    1642     $hostname = isset( $credentials['hostname'] ) ? $credentials['hostname'] : '';
    1643     $username = isset( $credentials['username'] ) ? $credentials['username'] : '';
    1644     $public_key = isset( $credentials['public_key'] ) ? $credentials['public_key'] : '';
    1645     $private_key = isset( $credentials['private_key'] ) ? $credentials['private_key'] : '';
    1646     $port = isset( $credentials['port'] ) ? $credentials['port'] : '';
     1710    $hostname        = isset( $credentials['hostname'] ) ? $credentials['hostname'] : '';
     1711    $username        = isset( $credentials['username'] ) ? $credentials['username'] : '';
     1712    $public_key      = isset( $credentials['public_key'] ) ? $credentials['public_key'] : '';
     1713    $private_key     = isset( $credentials['private_key'] ) ? $credentials['private_key'] : '';
     1714    $port            = isset( $credentials['port'] ) ? $credentials['port'] : '';
    16471715    $connection_type = isset( $credentials['connection_type'] ) ? $credentials['connection_type'] : '';
    16481716
    16491717    if ( $error ) {
    1650         $error_string = __('<strong>ERROR:</strong> There was an error connecting to the server, Please verify the settings are correct.');
    1651         if ( is_wp_error($error) )
     1718        $error_string = __( '<strong>ERROR:</strong> There was an error connecting to the server, Please verify the settings are correct.' );
     1719        if ( is_wp_error( $error ) ) {
    16521720            $error_string = esc_html( $error->get_error_message() );
     1721        }
    16531722        echo '<div id="message" class="error"><p>' . $error_string . '</p></div>';
    16541723    }
    16551724
    16561725    $types = array();
    1657     if ( extension_loaded('ftp') || extension_loaded('sockets') || function_exists('fsockopen') )
    1658         $types[ 'ftp' ] = __('FTP');
    1659     if ( extension_loaded('ftp') ) //Only this supports FTPS
    1660         $types[ 'ftps' ] = __('FTPS (SSL)');
    1661     if ( extension_loaded('ssh2') && function_exists('stream_get_contents') )
    1662         $types[ 'ssh' ] = __('SSH2');
     1726    if ( extension_loaded( 'ftp' ) || extension_loaded( 'sockets' ) || function_exists( 'fsockopen' ) ) {
     1727        $types['ftp'] = __( 'FTP' );
     1728    }
     1729    if ( extension_loaded( 'ftp' ) ) { //Only this supports FTPS
     1730        $types['ftps'] = __( 'FTPS (SSL)' );
     1731    }
     1732    if ( extension_loaded( 'ssh2' ) && function_exists( 'stream_get_contents' ) ) {
     1733        $types['ssh'] = __( 'SSH2' );
     1734    }
    16631735
    16641736    /**
     
    16781750
    16791751?>
    1680 <form action="<?php echo esc_url( $form_post ) ?>" method="post">
     1752<form action="<?php echo esc_url( $form_post ); ?>" method="post">
    16811753<div id="request-filesystem-credentials-form" class="request-filesystem-credentials-form">
    16821754<?php
     
    16881760echo "<$heading_tag id='request-filesystem-credentials-title'>" . __( 'Connection Information' ) . "</$heading_tag>";
    16891761?>
    1690 <p id="request-filesystem-credentials-desc"><?php
    1691     $label_user = __('Username');
    1692     $label_pass = __('Password');
    1693     _e('To perform the requested action, WordPress needs to access your web server.');
     1762<p id="request-filesystem-credentials-desc">
     1763<?php
     1764    $label_user = __( 'Username' );
     1765    $label_pass = __( 'Password' );
     1766    _e( 'To perform the requested action, WordPress needs to access your web server.' );
    16941767    echo ' ';
    1695     if ( ( isset( $types['ftp'] ) || isset( $types['ftps'] ) ) ) {
    1696         if ( isset( $types['ssh'] ) ) {
    1697             _e('Please enter your FTP or SSH credentials to proceed.');
    1698             $label_user = __('FTP/SSH Username');
    1699             $label_pass = __('FTP/SSH Password');
    1700         } else {
    1701             _e('Please enter your FTP credentials to proceed.');
    1702             $label_user = __('FTP Username');
    1703             $label_pass = __('FTP Password');
    1704         }
    1705         echo ' ';
    1706     }
    1707     _e('If you do not remember your credentials, you should contact your web host.');
     1768if ( ( isset( $types['ftp'] ) || isset( $types['ftps'] ) ) ) {
     1769    if ( isset( $types['ssh'] ) ) {
     1770        _e( 'Please enter your FTP or SSH credentials to proceed.' );
     1771        $label_user = __( 'FTP/SSH Username' );
     1772        $label_pass = __( 'FTP/SSH Password' );
     1773    } else {
     1774        _e( 'Please enter your FTP credentials to proceed.' );
     1775        $label_user = __( 'FTP Username' );
     1776        $label_pass = __( 'FTP Password' );
     1777    }
     1778    echo ' ';
     1779}
     1780    _e( 'If you do not remember your credentials, you should contact your web host.' );
    17081781
    17091782    $password_value = '';
    1710     if ( defined('FTP_PASS') ) {
    1711         $password_value = '*****';
    1712     }
    1713 ?></p>
     1783if ( defined( 'FTP_PASS' ) ) {
     1784    $password_value = '*****';
     1785}
     1786?>
     1787</p>
    17141788<label for="hostname">
    1715     <span class="field-title"><?php _e( 'Hostname' ) ?></span>
    1716     <input name="hostname" type="text" id="hostname" aria-describedby="request-filesystem-credentials-desc" class="code" placeholder="<?php esc_attr_e( 'example: www.wordpress.org' ) ?>" value="<?php echo esc_attr($hostname); if ( !empty($port) ) echo ":$port"; ?>"<?php disabled( defined('FTP_HOST') ); ?> />
     1789    <span class="field-title"><?php _e( 'Hostname' ); ?></span>
     1790    <input name="hostname" type="text" id="hostname" aria-describedby="request-filesystem-credentials-desc" class="code" placeholder="<?php esc_attr_e( 'example: www.wordpress.org' ); ?>" value="
     1791                                                                                                                                                        <?php
     1792                                                                                                                                                        echo esc_attr( $hostname );
     1793                                                                                                                                                        if ( ! empty( $port ) ) {
     1794                                                                                                                                                            echo ":$port";}
     1795?>
     1796"<?php disabled( defined( 'FTP_HOST' ) ); ?> />
    17171797</label>
    17181798<div class="ftp-username">
    17191799    <label for="username">
    17201800        <span class="field-title"><?php echo $label_user; ?></span>
    1721         <input name="username" type="text" id="username" value="<?php echo esc_attr($username) ?>"<?php disabled( defined('FTP_USER') ); ?> />
     1801        <input name="username" type="text" id="username" value="<?php echo esc_attr( $username ); ?>"<?php disabled( defined( 'FTP_USER' ) ); ?> />
    17221802    </label>
    17231803</div>
     
    17251805    <label for="password">
    17261806        <span class="field-title"><?php echo $label_pass; ?></span>
    1727         <input name="password" type="password" id="password" value="<?php echo $password_value; ?>"<?php disabled( defined('FTP_PASS') ); ?> />
    1728         <em><?php if ( ! defined('FTP_PASS') ) _e( 'This password will not be stored on the server.' ); ?></em>
     1807        <input name="password" type="password" id="password" value="<?php echo $password_value; ?>"<?php disabled( defined( 'FTP_PASS' ) ); ?> />
     1808        <em>
     1809        <?php
     1810        if ( ! defined( 'FTP_PASS' ) ) {
     1811            _e( 'This password will not be stored on the server.' );}
     1812?>
     1813</em>
    17291814    </label>
    17301815</div>
     
    17331818<?php
    17341819    $disabled = disabled( ( defined( 'FTP_SSL' ) && FTP_SSL ) || ( defined( 'FTP_SSH' ) && FTP_SSH ), true, false );
    1735     foreach ( $types as $name => $text ) : ?>
    1736     <label for="<?php echo esc_attr( $name ) ?>">
    1737         <input type="radio" name="connection_type" id="<?php echo esc_attr( $name ) ?>" value="<?php echo esc_attr( $name ) ?>"<?php checked( $name, $connection_type ); echo $disabled; ?> />
     1820foreach ( $types as $name => $text ) :
     1821    ?>
     1822    <label for="<?php echo esc_attr( $name ); ?>">
     1823        <input type="radio" name="connection_type" id="<?php echo esc_attr( $name ); ?>" value="<?php echo esc_attr( $name ); ?>"
     1824                                                                    <?php
     1825                                                                    checked( $name, $connection_type );
     1826                                                                    echo $disabled;
     1827?>
     1828 />
    17381829        <?php echo $text; ?>
    17391830    </label>
     
    17521843<legend><?php _e( 'Authentication Keys' ); ?></legend>
    17531844<label for="public_key">
    1754     <span class="field-title"><?php _e('Public Key:') ?></span>
    1755     <input name="public_key" type="text" id="public_key" aria-describedby="auth-keys-desc" value="<?php echo esc_attr($public_key) ?>"<?php disabled( defined('FTP_PUBKEY') ); ?> />
     1845    <span class="field-title"><?php _e( 'Public Key:' ); ?></span>
     1846    <input name="public_key" type="text" id="public_key" aria-describedby="auth-keys-desc" value="<?php echo esc_attr( $public_key ); ?>"<?php disabled( defined( 'FTP_PUBKEY' ) ); ?> />
    17561847</label>
    17571848<label for="private_key">
    1758     <span class="field-title"><?php _e('Private Key:') ?></span>
    1759     <input name="private_key" type="text" id="private_key" value="<?php echo esc_attr($private_key) ?>"<?php disabled( defined('FTP_PRIKEY') ); ?> />
     1849    <span class="field-title"><?php _e( 'Private Key:' ); ?></span>
     1850    <input name="private_key" type="text" id="private_key" value="<?php echo esc_attr( $private_key ); ?>"<?php disabled( defined( 'FTP_PRIKEY' ) ); ?> />
    17601851</label>
    1761 <p id="auth-keys-desc"><?php _e( 'Enter the location on the server where the public and private keys are located. If a passphrase is needed, enter that in the password field above.' ) ?></p>
     1852<p id="auth-keys-desc"><?php _e( 'Enter the location on the server where the public and private keys are located. If a passphrase is needed, enter that in the password field above.' ); ?></p>
    17621853</fieldset>
    17631854<?php
     
    17651856
    17661857foreach ( (array) $extra_fields as $field ) {
    1767     if ( isset( $submitted_form[ $field ] ) )
     1858    if ( isset( $submitted_form[ $field ] ) ) {
    17681859        echo '<input type="hidden" name="' . esc_attr( $field ) . '" value="' . esc_attr( $submitted_form[ $field ] ) . '" />';
     1860    }
    17691861}
    17701862?>
Note: See TracChangeset for help on using the changeset viewer.