Changeset 42343 for trunk/src/wp-admin/includes/file.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/file.php
r42246 r42343 106 106 if ( ! empty( $home ) && 0 !== strcasecmp( $home, $siteurl ) ) { 107 107 $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 ); 111 111 } else { 112 112 $home_path = ABSPATH; … … 157 157 $files2 = list_files( $folder . $file, $levels - 1 ); 158 158 if ( $files2 ) { 159 $files = array_merge( $files, $files2 );159 $files = array_merge( $files, $files2 ); 160 160 } else { 161 161 $files[] = $folder . $file . '/'; … … 368 368 } 369 369 370 $plugin = null;371 $theme = null;370 $plugin = null; 371 $theme = null; 372 372 $real_file = null; 373 373 if ( ! empty( $args['plugin'] ) ) { … … 435 435 break; 436 436 case 'css': 437 $style_files = $theme->get_files( 'css', -1 );437 $style_files = $theme->get_files( 'css', -1 ); 438 438 $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 ); 440 440 break; 441 441 default: … … 494 494 if ( $is_active && 'php' === $extension ) { 495 495 496 $scrape_key = md5( rand() );497 $transient = 'scrape_key_' . $scrape_key;496 $scrape_key = md5( rand() ); 497 $transient = 'scrape_key_' . $scrape_key; 498 498 $scrape_nonce = strval( rand() ); 499 499 set_transient( $transient, $scrape_nonce, 60 ); // It shouldn't take more than 60 seconds to make the two loopback requests. 500 500 501 $cookies = wp_unslash( $_COOKIE );501 $cookies = wp_unslash( $_COOKIE ); 502 502 $scrape_params = array( 503 'wp_scrape_key' => $scrape_key,503 'wp_scrape_key' => $scrape_key, 504 504 'wp_scrape_nonce' => $scrape_nonce, 505 505 ); 506 $headers = array(506 $headers = array( 507 507 'Cache-Control' => 'no-cache', 508 508 ); … … 520 520 521 521 $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 ######"; 523 523 524 524 // Attempt loopback request to editor to see if user just whitescreened themselves. … … 529 529 array( 530 530 'theme' => $stylesheet, 531 'file' => $file,531 'file' => $file, 532 532 ), 533 533 admin_url( 'theme-editor.php' ) … … 536 536 $url = admin_url(); 537 537 } 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 ); 541 541 $scrape_result_position = strpos( $body, $needle_start ); 542 542 543 543 $loopback_request_failure = array( 544 'code' => 'loopback_request_failed',544 'code' => 'loopback_request_failed', 545 545 '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.' ), 546 546 ); 547 $json_parse_failure = array(547 $json_parse_failure = array( 548 548 'code' => 'json_parse_error', 549 549 ); … … 555 555 $error_output = substr( $body, $scrape_result_position + strlen( $needle_start ) ); 556 556 $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 ); 558 558 if ( empty( $result ) ) { 559 559 $result = $json_parse_failure; … … 563 563 // Try making request to homepage as well to see if visitors have been whitescreened. 564 564 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 ); 569 569 $scrape_result_position = strpos( $body, $needle_start ); 570 570 … … 574 574 $error_output = substr( $body, $scrape_result_position + strlen( $needle_start ) ); 575 575 $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 ); 577 577 if ( empty( $result ) ) { 578 578 $result = $json_parse_failure; … … 643 643 $temp_filename .= '-' . wp_generate_password( 6, false ); 644 644 $temp_filename .= '.tmp'; 645 $temp_filename = $dir . wp_unique_filename( $dir, $temp_filename );645 $temp_filename = $dir . wp_unique_filename( $dir, $temp_filename ); 646 646 647 647 $fp = @fopen( $temp_filename, 'x' ); … … 670 670 $code = validate_file( $file, $allowed_files ); 671 671 672 if ( !$code )672 if ( ! $code ) { 673 673 return $file; 674 } 674 675 675 676 switch ( $code ) { 676 case 1 677 case 1: 677 678 wp_die( __( 'Sorry, that file cannot be edited.' ) ); 678 679 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: 683 684 wp_die( __( 'Sorry, that file cannot be edited.' ) ); 684 685 } … … 757 758 __( 'Missing a temporary folder.' ), 758 759 __( 'Failed to write file to disk.' ), 759 __( 'File upload stopped by extension.' ) 760 __( 'File upload stopped by extension.' ), 760 761 ); 761 762 } … … 767 768 // If you override this, you must provide $ext and $type!! 768 769 $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; 770 771 771 772 // A correct form post will pass this test. … … 797 798 // A correct MIME type will pass this test. Override $mimes or use the upload_mimes filter. 798 799 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']; 802 803 $proper_filename = empty( $wp_filetype['proper_filename'] ) ? '' : $wp_filetype['proper_filename']; 803 804 … … 806 807 $file['name'] = $proper_filename; 807 808 } 808 if ( ( ! $type || ! $ext ) && ! current_user_can( 'unfiltered_upload' ) ) {809 if ( ( ! $type || ! $ext ) && ! current_user_can( 'unfiltered_upload' ) ) { 809 810 return call_user_func_array( $upload_error_handler, array( &$file, __( 'Sorry, this file type is not permitted for security reasons.' ) ) ); 810 811 } … … 829 830 $new_file = $uploads['path'] . "/$filename"; 830 831 831 832 /** 832 833 * Filters whether to short-circuit moving the uploaded file after passing all checks. 833 834 * … … 859 860 $error_path = basename( $uploads['basedir'] ) . $uploads['subdir']; 860 861 } 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 ) ); 862 863 } 863 864 } 864 865 865 866 // Set correct file permissions. 866 $stat = stat( dirname( $new_file ));867 $stat = stat( dirname( $new_file ) ); 867 868 $perms = $stat['mode'] & 0000666; 868 869 @ chmod( $new_file, $perms ); … … 889 890 * @param string $context The type of upload action. Values include 'upload' or 'sideload'. 890 891 */ 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 ); 896 899 } 897 900 … … 967 970 function download_url( $url, $timeout = 300 ) { 968 971 //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 } 971 975 972 976 $url_filename = basename( parse_url( $url, PHP_URL_PATH ) ); 973 977 974 978 $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 ); 979 990 980 991 if ( is_wp_error( $response ) ) { … … 983 994 } 984 995 985 if ( 200 != wp_remote_retrieve_response_code( $response ) ) {996 if ( 200 != wp_remote_retrieve_response_code( $response ) ) { 986 997 unlink( $tmpfname ); 987 998 return new WP_Error( 'http_404', trim( wp_remote_retrieve_response_message( $response ) ) ); … … 1010 1021 */ 1011 1022 function verify_file_md5( $filename, $expected_md5 ) { 1012 if ( 32 == strlen( $expected_md5 ) ) 1023 if ( 32 == strlen( $expected_md5 ) ) { 1013 1024 $expected_raw_md5 = pack( 'H*', $expected_md5 ); 1014 elseif ( 24 == strlen( $expected_md5 ) )1025 } elseif ( 24 == strlen( $expected_md5 ) ) { 1015 1026 $expected_raw_md5 = base64_decode( $expected_md5 ); 1016 else1027 } else { 1017 1028 return false; // unknown format 1029 } 1018 1030 1019 1031 $file_md5 = md5_file( $filename, true ); 1020 1032 1021 if ( $file_md5 === $expected_raw_md5 ) 1033 if ( $file_md5 === $expected_raw_md5 ) { 1022 1034 return true; 1035 } 1023 1036 1024 1037 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 ) ) ); … … 1040 1053 * @return mixed WP_Error on failure, True on success 1041 1054 */ 1042 function unzip_file( $file, $to) {1055 function unzip_file( $file, $to ) { 1043 1056 global $wp_filesystem; 1044 1057 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 } 1047 1061 1048 1062 // Unzip can use a lot of memory, but not this much hopefully. … … 1050 1064 1051 1065 $needed_dirs = array(); 1052 $to = trailingslashit($to);1066 $to = trailingslashit( $to ); 1053 1067 1054 1068 // Determine any parent dir's needed (of the upgrade directory) 1055 if ( ! $wp_filesystem->is_dir( $to) ) { //Only do parents if no children exist1056 $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 ] ) ) { 1059 1073 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. 1063 1078 continue; 1064 1065 if ( ! $wp_filesystem->is_dir($dir) ) 1079 } 1080 1081 if ( ! $wp_filesystem->is_dir( $dir ) ) { 1066 1082 $needed_dirs[] = $dir; 1067 else1083 } else { 1068 1084 break; // A folder exists, therefor, we dont need the check the levels below this 1085 } 1069 1086 } 1070 1087 } … … 1078 1095 */ 1079 1096 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 ); 1081 1098 if ( true === $result ) { 1082 1099 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() ) { 1085 1102 return $result; 1103 } 1086 1104 } 1087 1105 } 1088 1106 // 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 ); 1090 1108 } 1091 1109 … … 1105 1123 * @return mixed WP_Error on failure, True on success 1106 1124 */ 1107 function _unzip_file_ziparchive( $file, $to, $needed_dirs = array() ) {1125 function _unzip_file_ziparchive( $file, $to, $needed_dirs = array() ) { 1108 1126 global $wp_filesystem; 1109 1127 … … 1111 1129 1112 1130 $zopen = $z->open( $file, ZIPARCHIVE::CHECKCONS ); 1113 if ( true !== $zopen ) 1131 if ( true !== $zopen ) { 1114 1132 return new WP_Error( 'incompatible_archive', __( 'Incompatible Archive.' ), array( 'ziparchive_error' => $zopen ) ); 1133 } 1115 1134 1116 1135 $uncompressed_size = 0; 1117 1136 1118 1137 for ( $i = 0; $i < $z->numFiles; $i++ ) { 1119 if ( ! $info = $z->statIndex( $i) )1138 if ( ! $info = $z->statIndex( $i ) ) { 1120 1139 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 1123 1143 continue; 1144 } 1124 1145 1125 1146 // Don't extract invalid files: … … 1146 1167 if ( wp_doing_cron() ) { 1147 1168 $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 ) { 1149 1170 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 ); 1153 1175 foreach ( $needed_dirs as $dir ) { 1154 1176 // 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) 1156 1178 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 1158 1181 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 ) ) { 1162 1186 $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 ); 1167 1191 1168 1192 // Create those directories if need be: … … 1173 1197 } 1174 1198 } 1175 unset( $needed_dirs);1199 unset( $needed_dirs ); 1176 1200 1177 1201 for ( $i = 0; $i < $z->numFiles; $i++ ) { 1178 if ( ! $info = $z->statIndex( $i) )1202 if ( ! $info = $z->statIndex( $i ) ) { 1179 1203 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 1182 1207 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 1185 1211 continue; 1212 } 1186 1213 1187 1214 // Don't extract invalid files: … … 1190 1217 } 1191 1218 1192 $contents = $z->getFromIndex( $i);1193 if ( false === $contents ) 1219 $contents = $z->getFromIndex( $i ); 1220 if ( false === $contents ) { 1194 1221 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 ) ) { 1197 1225 return new WP_Error( 'copy_failed_ziparchive', __( 'Could not copy file.' ), $info['name'] ); 1226 } 1198 1227 } 1199 1228 … … 1218 1247 * @return mixed WP_Error on failure, True on success 1219 1248 */ 1220 function _unzip_file_pclzip( $file, $to, $needed_dirs = array()) {1249 function _unzip_file_pclzip( $file, $to, $needed_dirs = array() ) { 1221 1250 global $wp_filesystem; 1222 1251 1223 1252 mbstring_binary_safe_encoding(); 1224 1253 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 ); 1230 1259 1231 1260 reset_mbstring_encoding(); 1232 1261 1233 1262 // 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 ) ) { 1238 1268 return new WP_Error( 'empty_archive_pclzip', __( 'Empty archive.' ) ); 1269 } 1239 1270 1240 1271 $uncompressed_size = 0; … … 1242 1273 // Determine any children directories needed (From within the archive) 1243 1274 foreach ( $archive_files as $file ) { 1244 if ( '__MACOSX/' === substr( $file['filename'], 0, 9) )// Skip the OS X-created __MACOSX directory1275 if ( '__MACOSX/' === substr( $file['filename'], 0, 9 ) ) { // Skip the OS X-created __MACOSX directory 1245 1276 continue; 1277 } 1246 1278 1247 1279 $uncompressed_size += $file['size']; 1248 1280 1249 $needed_dirs[] = $to . untrailingslashit( $file['folder'] ? $file['filename'] : dirname( $file['filename']) );1281 $needed_dirs[] = $to . untrailingslashit( $file['folder'] ? $file['filename'] : dirname( $file['filename'] ) ); 1250 1282 } 1251 1283 … … 1257 1289 if ( wp_doing_cron() ) { 1258 1290 $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 ) { 1260 1292 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 ); 1264 1297 foreach ( $needed_dirs as $dir ) { 1265 1298 // 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) 1267 1300 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 1269 1303 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 ) ) { 1273 1308 $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 ); 1278 1313 1279 1314 // Create those directories if need be: 1280 1315 foreach ( $needed_dirs as $_dir ) { 1281 1316 // 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 ) ) { 1283 1318 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 ); 1286 1322 1287 1323 // Extract the files from the zip 1288 1324 foreach ( $archive_files as $file ) { 1289 if ( $file['folder'] ) 1325 if ( $file['folder'] ) { 1290 1326 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 1293 1330 continue; 1331 } 1294 1332 1295 1333 // Don't extract invalid files: … … 1298 1336 } 1299 1337 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 ) ) { 1301 1339 return new WP_Error( 'copy_failed_pclzip', __( 'Could not copy file.' ), $file['filename'] ); 1340 } 1302 1341 } 1303 1342 return true; … … 1317 1356 * @return mixed WP_Error on failure, True on success. 1318 1357 */ 1319 function copy_dir( $from, $to, $skip_list = array() ) {1358 function copy_dir( $from, $to, $skip_list = array() ) { 1320 1359 global $wp_filesystem; 1321 1360 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 ); 1326 1365 1327 1366 foreach ( (array) $dirlist as $filename => $fileinfo ) { 1328 if ( in_array( $filename, $skip_list ) ) 1367 if ( in_array( $filename, $skip_list ) ) { 1329 1368 continue; 1369 } 1330 1370 1331 1371 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 ) ) { 1333 1373 // If copy failed, chmod file to 0644 and try again. 1334 1374 $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 ) ) { 1336 1376 return new WP_Error( 'copy_failed_copy_dir', __( 'Could not copy file.' ), $to . $filename ); 1377 } 1337 1378 } 1338 1379 } 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 ) ) { 1341 1382 return new WP_Error( 'mkdir_failed_copy_dir', __( 'Could not create directory.' ), $to . $filename ); 1383 } 1342 1384 } 1343 1385 … … 1345 1387 $sub_skip_list = array(); 1346 1388 foreach ( $skip_list as $skip_item ) { 1347 if ( 0 === strpos( $skip_item, $filename . '/' ) ) 1389 if ( 0 === strpos( $skip_item, $filename . '/' ) ) { 1348 1390 $sub_skip_list[] = preg_replace( '!^' . preg_quote( $filename, '!' ) . '/!i', '', $skip_item ); 1391 } 1349 1392 } 1350 1393 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 ) ) { 1353 1396 return $result; 1397 } 1354 1398 } 1355 1399 } … … 1377 1421 global $wp_filesystem; 1378 1422 1379 require_once( ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php');1423 require_once( ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php' ); 1380 1424 1381 1425 $method = get_filesystem_method( $args, $context, $allow_relaxed_file_ownership ); 1382 1426 1383 if ( ! $method ) 1427 if ( ! $method ) { 1384 1428 return false; 1429 } 1385 1430 1386 1431 if ( ! class_exists( "WP_Filesystem_$method" ) ) { … … 1398 1443 $abstraction_file = apply_filters( 'filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method ); 1399 1444 1400 if ( ! file_exists( $abstraction_file) )1445 if ( ! file_exists( $abstraction_file ) ) { 1401 1446 return; 1402 1403 require_once($abstraction_file); 1447 } 1448 1449 require_once( $abstraction_file ); 1404 1450 } 1405 1451 $method = "WP_Filesystem_$method"; 1406 1452 1407 $wp_filesystem = new $method( $args);1453 $wp_filesystem = new $method( $args ); 1408 1454 1409 1455 //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() ) { 1416 1464 return false; 1417 1418 if ( !$wp_filesystem->connect() ) 1465 } 1466 1467 if ( ! $wp_filesystem->connect() ) { 1419 1468 return false; //There was an error connecting to the server. 1469 } 1420 1470 1421 1471 // 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 } 1426 1478 1427 1479 return true; … … 1455 1507 */ 1456 1508 function 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' 1458 1510 1459 1511 if ( ! $context ) { … … 1471 1523 1472 1524 $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' ); 1474 1526 if ( $temp_handle ) { 1475 1527 1476 1528 // Attempt to determine the file owner of the WordPress files, and that of newly created files 1477 1529 $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__ ); 1480 1532 $temp_file_owner = @fileowner( $temp_file_name ); 1481 1533 } … … 1484 1536 // WordPress is creating files as the same owner as the WordPress files, 1485 1537 // this means it's safe to modify & create new files via PHP. 1486 $method = 'direct';1538 $method = 'direct'; 1487 1539 $GLOBALS['_wp_filesystem_direct_method'] = 'file_owner'; 1488 1540 } elseif ( $allow_relaxed_file_ownership ) { 1489 1541 // The $context directory is writable, and $allow_relaxed_file_ownership is set, this means we can modify files 1490 1542 // safely in this directory. This mode doesn't create new files, only alter existing ones. 1491 $method = 'direct';1543 $method = 'direct'; 1492 1544 $GLOBALS['_wp_filesystem_direct_method'] = 'relaxed_ownership'; 1493 1545 } 1494 1546 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 } 1503 1561 1504 1562 /** … … 1567 1625 */ 1568 1626 $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 ) { 1570 1628 return $req_cred; 1571 1572 if ( empty($type) ) { 1629 } 1630 1631 if ( empty( $type ) ) { 1573 1632 $type = get_filesystem_method( array(), $context, $allow_relaxed_file_ownership ); 1574 1633 } 1575 1634 1576 if ( 'direct' == $type ) 1635 if ( 'direct' == $type ) { 1577 1636 return true; 1578 1579 if ( is_null( $extra_fields ) ) 1637 } 1638 1639 if ( is_null( $extra_fields ) ) { 1580 1640 $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 ); 1583 1649 1584 1650 $submitted_form = wp_unslash( $_POST ); … … 1597 1663 1598 1664 // 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'] : '' ); 1602 1668 1603 1669 // 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'] : '' ); 1606 1672 1607 1673 // 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 } 1614 1681 } else { 1615 unset( $credentials['port']);1682 unset( $credentials['port'] ); 1616 1683 } 1617 1684 … … 1627 1694 if ( ! $error && 1628 1695 ( 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'] ) ) 1631 1698 ) ) { 1632 1699 $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. 1634 1701 $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'] ); 1637 1705 if ( ! wp_installing() ) { 1638 1706 update_option( 'ftp_credentials', $stored_credentials ); … … 1640 1708 return $credentials; 1641 1709 } 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'] : ''; 1647 1715 $connection_type = isset( $credentials['connection_type'] ) ? $credentials['connection_type'] : ''; 1648 1716 1649 1717 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 ) ) { 1652 1720 $error_string = esc_html( $error->get_error_message() ); 1721 } 1653 1722 echo '<div id="message" class="error"><p>' . $error_string . '</p></div>'; 1654 1723 } 1655 1724 1656 1725 $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 } 1663 1735 1664 1736 /** … … 1678 1750 1679 1751 ?> 1680 <form action="<?php echo esc_url( $form_post ) ?>" method="post">1752 <form action="<?php echo esc_url( $form_post ); ?>" method="post"> 1681 1753 <div id="request-filesystem-credentials-form" class="request-filesystem-credentials-form"> 1682 1754 <?php … … 1688 1760 echo "<$heading_tag id='request-filesystem-credentials-title'>" . __( 'Connection Information' ) . "</$heading_tag>"; 1689 1761 ?> 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.' ); 1694 1767 echo ' '; 1695 1696 1697 _e('Please enter your FTP or SSH credentials to proceed.');1698 $label_user = __('FTP/SSH Username');1699 $label_pass = __('FTP/SSH Password');1700 1701 _e('Please enter your FTP credentials to proceed.');1702 $label_user = __('FTP Username');1703 $label_pass = __('FTP Password');1704 1705 1706 1707 _e( 'If you do not remember your credentials, you should contact your web host.');1768 if ( ( 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.' ); 1708 1781 1709 1782 $password_value = ''; 1710 if ( defined('FTP_PASS') ) { 1711 $password_value = '*****'; 1712 } 1713 ?></p> 1783 if ( defined( 'FTP_PASS' ) ) { 1784 $password_value = '*****'; 1785 } 1786 ?> 1787 </p> 1714 1788 <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' ) ); ?> /> 1717 1797 </label> 1718 1798 <div class="ftp-username"> 1719 1799 <label for="username"> 1720 1800 <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' ) ); ?> /> 1722 1802 </label> 1723 1803 </div> … … 1725 1805 <label for="password"> 1726 1806 <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> 1729 1814 </label> 1730 1815 </div> … … 1733 1818 <?php 1734 1819 $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; ?> /> 1820 foreach ( $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 /> 1738 1829 <?php echo $text; ?> 1739 1830 </label> … … 1752 1843 <legend><?php _e( 'Authentication Keys' ); ?></legend> 1753 1844 <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' ) ); ?> /> 1756 1847 </label> 1757 1848 <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' ) ); ?> /> 1760 1851 </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> 1762 1853 </fieldset> 1763 1854 <?php … … 1765 1856 1766 1857 foreach ( (array) $extra_fields as $field ) { 1767 if ( isset( $submitted_form[ $field ] ) ) 1858 if ( isset( $submitted_form[ $field ] ) ) { 1768 1859 echo '<input type="hidden" name="' . esc_attr( $field ) . '" value="' . esc_attr( $submitted_form[ $field ] ) . '" />'; 1860 } 1769 1861 } 1770 1862 ?>
Note: See TracChangeset
for help on using the changeset viewer.