Replace usages of basename() with wp_basename() in order to support multibyte filenames

This is focused on the pieces of code that touch media files and the tests that support them. `basename` isn't multibyte compatible out of the box. See http://php.net/basename and https://bugs.php.net/bug.php?id=62119.

See #43170.
Props Viper007Bond.


git-svn-id: https://develop.svn.wordpress.org/trunk@44785 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Aaron Jorbin
2019-03-01 20:57:26 +00:00
parent 4c45ff7c43
commit e421f262dc
32 changed files with 101 additions and 101 deletions

View File

@@ -820,7 +820,7 @@ endif;
return $this->finished();
} elseif ( $width > $max_width ) {
$oitar = $width / $max_width;
$image = wp_crop_image( $attachment_id, 0, 0, $width, $height, $max_width, $height / $oitar, false, str_replace( basename( $file ), 'midsize-' . basename( $file ), $file ) );
$image = wp_crop_image( $attachment_id, 0, 0, $width, $height, $max_width, $height / $oitar, false, str_replace( wp_basename( $file ), 'midsize-' . wp_basename( $file ), $file ) );
if ( ! $image || is_wp_error( $image ) ) {
wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
}
@@ -828,7 +828,7 @@ endif;
/** This filter is documented in wp-admin/custom-header.php */
$image = apply_filters( 'wp_create_file_in_uploads', $image, $attachment_id ); // For replication
$url = str_replace( basename( $url ), basename( $image ), $url );
$url = str_replace( wp_basename( $url ), wp_basename( $image ), $url );
$width = $width / $oitar;
$height = $height / $oitar;
} else {
@@ -895,7 +895,7 @@ endif;
$url = $file['url'];
$type = $file['type'];
$file = $file['file'];
$filename = basename( $file );
$filename = wp_basename( $file );
// Construct the object array
$object = array(
@@ -984,7 +984,7 @@ endif;
$this->set_header_image( compact( 'url', 'attachment_id', 'width', 'height' ) );
// Cleanup.
$medium = str_replace( basename( $original ), 'midsize-' . basename( $original ), $original );
$medium = str_replace( wp_basename( $original ), 'midsize-' . wp_basename( $original ), $original );
if ( file_exists( $medium ) ) {
wp_delete_file( $medium );
}
@@ -1208,14 +1208,14 @@ endif;
final public function create_attachment_object( $cropped, $parent_attachment_id ) {
$parent = get_post( $parent_attachment_id );
$parent_url = wp_get_attachment_url( $parent->ID );
$url = str_replace( basename( $parent_url ), basename( $cropped ), $parent_url );
$url = str_replace( wp_basename( $parent_url ), wp_basename( $cropped ), $parent_url );
$size = @getimagesize( $cropped );
$image_type = ( $size ) ? $size['mime'] : 'image/jpeg';
$object = array(
'ID' => $parent_attachment_id,
'post_title' => basename( $cropped ),
'post_title' => wp_basename( $cropped ),
'post_mime_type' => $image_type,
'guid' => $url,
'context' => 'custom-header',