633 // Roll-back file change. |
633 // Roll-back file change. |
634 file_put_contents( $real_file, $previous_content ); |
634 file_put_contents( $real_file, $previous_content ); |
635 wp_opcache_invalidate( $real_file, true ); |
635 wp_opcache_invalidate( $real_file, true ); |
636 |
636 |
637 if ( ! isset( $result['message'] ) ) { |
637 if ( ! isset( $result['message'] ) ) { |
638 $message = __( 'Something went wrong.' ); |
638 $message = __( 'An error occurred. Please try again later.' ); |
639 } else { |
639 } else { |
640 $message = $result['message']; |
640 $message = $result['message']; |
641 unset( $result['message'] ); |
641 unset( $result['message'] ); |
642 } |
642 } |
643 |
643 |
1239 unlink( $tmpfname_disposition ); |
1239 unlink( $tmpfname_disposition ); |
1240 } |
1240 } |
1241 } |
1241 } |
1242 } |
1242 } |
1243 |
1243 |
|
1244 $mime_type = wp_remote_retrieve_header( $response, 'content-type' ); |
|
1245 if ( $mime_type && 'tmp' === pathinfo( $tmpfname, PATHINFO_EXTENSION ) ) { |
|
1246 $valid_mime_types = array_flip( get_allowed_mime_types() ); |
|
1247 if ( ! empty( $valid_mime_types[ $mime_type ] ) ) { |
|
1248 $extensions = explode( '|', $valid_mime_types[ $mime_type ] ); |
|
1249 $new_image_name = substr( $tmpfname, 0, -4 ) . ".{$extensions[0]}"; |
|
1250 if ( 0 === validate_file( $new_image_name ) ) { |
|
1251 if ( rename( $tmpfname, $new_image_name ) ) { |
|
1252 $tmpfname = $new_image_name; |
|
1253 } |
|
1254 |
|
1255 if ( ( $tmpfname !== $new_image_name ) && file_exists( $new_image_name ) ) { |
|
1256 unlink( $new_image_name ); |
|
1257 } |
|
1258 } |
|
1259 } |
|
1260 } |
|
1261 |
1244 $content_md5 = wp_remote_retrieve_header( $response, 'Content-MD5' ); |
1262 $content_md5 = wp_remote_retrieve_header( $response, 'Content-MD5' ); |
1245 |
1263 |
1246 if ( $content_md5 ) { |
1264 if ( $content_md5 ) { |
1247 $md5_check = verify_file_md5( $tmpfname, $content_md5 ); |
1265 $md5_check = verify_file_md5( $tmpfname, $content_md5 ); |
1248 |
1266 |
1397 /* translators: %s: The filename of the package. */ |
1415 /* translators: %s: The filename of the package. */ |
1398 __( 'The authenticity of %s could not be verified as signature verification is unavailable on this system.' ), |
1416 __( 'The authenticity of %s could not be verified as signature verification is unavailable on this system.' ), |
1399 '<span class="code">' . esc_html( $filename_for_errors ) . '</span>' |
1417 '<span class="code">' . esc_html( $filename_for_errors ) . '</span>' |
1400 ), |
1418 ), |
1401 ( ! function_exists( 'sodium_crypto_sign_verify_detached' ) ? 'sodium_crypto_sign_verify_detached' : 'sha384' ) |
1419 ( ! function_exists( 'sodium_crypto_sign_verify_detached' ) ? 'sodium_crypto_sign_verify_detached' : 'sha384' ) |
1402 ); |
|
1403 } |
|
1404 |
|
1405 // Check for an edge-case affecting PHP Maths abilities. |
|
1406 if ( |
|
1407 ! extension_loaded( 'sodium' ) && |
|
1408 in_array( PHP_VERSION_ID, array( 70200, 70201, 70202 ), true ) && |
|
1409 extension_loaded( 'opcache' ) |
|
1410 ) { |
|
1411 /* |
|
1412 * Sodium_Compat isn't compatible with PHP 7.2.0~7.2.2 due to a bug in the PHP Opcache extension, bail early as it'll fail. |
|
1413 * https://bugs.php.net/bug.php?id=75938 |
|
1414 */ |
|
1415 return new WP_Error( |
|
1416 'signature_verification_unsupported', |
|
1417 sprintf( |
|
1418 /* translators: %s: The filename of the package. */ |
|
1419 __( 'The authenticity of %s could not be verified as signature verification is unavailable on this system.' ), |
|
1420 '<span class="code">' . esc_html( $filename_for_errors ) . '</span>' |
|
1421 ), |
|
1422 array( |
|
1423 'php' => PHP_VERSION, |
|
1424 'sodium' => defined( 'SODIUM_LIBRARY_VERSION' ) ? SODIUM_LIBRARY_VERSION : ( defined( 'ParagonIE_Sodium_Compat::VERSION_STRING' ) ? ParagonIE_Sodium_Compat::VERSION_STRING : false ), |
|
1425 ) |
|
1426 ); |
1420 ); |
1427 } |
1421 } |
1428 |
1422 |
1429 // Verify runtime speed of Sodium_Compat is acceptable. |
1423 // Verify runtime speed of Sodium_Compat is acceptable. |
1430 if ( ! extension_loaded( 'sodium' ) && ! ParagonIE_Sodium_Compat::polyfill_is_fast() ) { |
1424 if ( ! extension_loaded( 'sodium' ) && ! ParagonIE_Sodium_Compat::polyfill_is_fast() ) { |
2494 $stored_credentials['private_key'], |
2488 $stored_credentials['private_key'], |
2495 $stored_credentials['public_key'] |
2489 $stored_credentials['public_key'] |
2496 ); |
2490 ); |
2497 |
2491 |
2498 if ( ! wp_installing() ) { |
2492 if ( ! wp_installing() ) { |
2499 update_option( 'ftp_credentials', $stored_credentials ); |
2493 update_option( 'ftp_credentials', $stored_credentials, false ); |
2500 } |
2494 } |
2501 |
2495 |
2502 return $credentials; |
2496 return $credentials; |
2503 } |
2497 } |
2504 |
2498 |