495 | | * @return mixed WP_Error on failure, string Filename on success. |
| 495 | * @param mixed $verify Whether to attempt download verification using the Content-MD5 header if it exists, bool to use Content-MD5 header, or string for a hex hash, or URL to MD5 file |
| 496 | * @param bool $force_verify Whether to force verification, despite the existence of the MD5 |
| 497 | * @param bool $full_response Whether to return the full response instead of just the filename |
| 498 | * @return mixed WP_Error on failure, string Filename or HTTP API response array on success. |
518 | | return $tmpfname; |
| 521 | if ( is_bool( $verify ) ) { |
| 522 | $content_md5 = wp_remote_retrieve_header( $response, 'content-md5' ); |
| 523 | if ( ! $content_md5 && $force_verify ) |
| 524 | return new WP_Error( 'download_verification_failed', __( 'A Content-MD5 header was not found.' ) ); |
| 525 | } else if ( preg_match( '!^(http|https|ftp)://!i', $verify ) ) { |
| 526 | $md5response = wp_remote_get( $verify ); |
| 527 | if ( ( is_wp_error ( $md5response ) || (int) wp_remote_retrieve_response_code ( $md5response ) !== 200 ) && $force_verify ) |
| 528 | return new WP_Error( 'download_verification_failed', sprintf( __( 'Failed to retrieve the specified MD5 file from <span class="code">%s</span>.' ), $verify ) ); |
| 529 | else |
| 530 | $content_md5 = current( explode( ' ' , wp_remote_retrieve_body( $md5response ) ) ); |
| 531 | } else { |
| 532 | $content_md5 = $verify; |
| 533 | } |
| 534 | |
| 535 | if ( ( ! empty( $content_md5 ) && $verify ) || $force_verify ) { |
| 536 | $md5_file = md5_file( $response['filename'] ); |
| 537 | if ( $md5_file != $content_md5 ) |
| 538 | return new WP_Error( 'download_verification_failed', sprintf( __( 'The checksum of the download (%1$s) does not match the provided checksum value (%2$s).' ), $md5_file, $content_md5 ) ); |
| 539 | } |
| 540 | |
| 541 | if ( $full_response ) |
| 542 | return $response; |
| 543 | else |
| 544 | return $tmpfname; |