Media: when calling `pathinfo()`, also pass a `PATHINFO_*` constant to avoid array notices for unset keys.
Props JaworskiMatt. Fixes #37608. Built from https://develop.svn.wordpress.org/trunk@38294 git-svn-id: http://core.svn.wordpress.org/trunk@38235 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
d73964aab6
commit
7ac88c02fa
|
@ -77,9 +77,10 @@ $wp_file_descriptions = array(
|
|||
function get_file_description( $file ) {
|
||||
global $wp_file_descriptions, $allowed_files;
|
||||
|
||||
$relative_pathinfo = pathinfo( $file );
|
||||
$dirname = pathinfo( $file, PATHINFO_DIRNAME );
|
||||
|
||||
$file_path = $allowed_files[ $file ];
|
||||
if ( isset( $wp_file_descriptions[ basename( $file ) ] ) && '.' === $relative_pathinfo['dirname'] ) {
|
||||
if ( isset( $wp_file_descriptions[ basename( $file ) ] ) && '.' === $dirname ) {
|
||||
return $wp_file_descriptions[ basename( $file ) ];
|
||||
} elseif ( file_exists( $file_path ) && is_file( $file_path ) ) {
|
||||
$template_data = implode( '', file( $file_path ) );
|
||||
|
|
|
@ -762,29 +762,34 @@ function wp_save_image( $post_id ) {
|
|||
|
||||
// Generate new filename.
|
||||
$path = get_attached_file( $post_id );
|
||||
$path_parts = pathinfo( $path );
|
||||
$filename = $path_parts['filename'];
|
||||
|
||||
$basename = pathinfo( $path, PATHINFO_BASENAME );
|
||||
$dirname = pathinfo( $path, PATHINFO_DIRNAME );
|
||||
$ext = pathinfo( $path, PATHINFO_EXTENSION );
|
||||
$filename = pathinfo( $path, PATHINFO_FILENAME );
|
||||
$suffix = time() . rand(100, 999);
|
||||
|
||||
if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE &&
|
||||
isset($backup_sizes['full-orig']) && $backup_sizes['full-orig']['file'] != $path_parts['basename'] ) {
|
||||
isset($backup_sizes['full-orig']) && $backup_sizes['full-orig']['file'] != $basename ) {
|
||||
|
||||
if ( 'thumbnail' == $target )
|
||||
$new_path = "{$path_parts['dirname']}/{$filename}-temp.{$path_parts['extension']}";
|
||||
else
|
||||
if ( 'thumbnail' == $target ) {
|
||||
$new_path = "{$dirname}/{$filename}-temp.{$ext}";
|
||||
} else {
|
||||
$new_path = $path;
|
||||
}
|
||||
} else {
|
||||
while ( true ) {
|
||||
$filename = preg_replace( '/-e([0-9]+)$/', '', $filename );
|
||||
$filename .= "-e{$suffix}";
|
||||
$new_filename = "{$filename}.{$path_parts['extension']}";
|
||||
$new_path = "{$path_parts['dirname']}/$new_filename";
|
||||
if ( file_exists($new_path) )
|
||||
$new_filename = "{$filename}.{$ext}";
|
||||
$new_path = "{$dirname}/$new_filename";
|
||||
if ( file_exists($new_path) ) {
|
||||
$suffix++;
|
||||
else
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Save the full-size file, also needed to create sub-sizes.
|
||||
if ( !wp_save_image_file($new_path, $img, $post->post_mime_type, $post_id) ) {
|
||||
|
@ -792,18 +797,19 @@ function wp_save_image( $post_id ) {
|
|||
return $return;
|
||||
}
|
||||
|
||||
if ( 'nothumb' == $target || 'all' == $target || 'full' == $target || $scaled ) {
|
||||
if ( 'nothumb' === $target || 'all' === $target || 'full' === $target || $scaled ) {
|
||||
$tag = false;
|
||||
if ( isset( $backup_sizes['full-orig'] ) ) {
|
||||
if ( ( !defined('IMAGE_EDIT_OVERWRITE') || !IMAGE_EDIT_OVERWRITE ) && $backup_sizes['full-orig']['file'] != $path_parts['basename'] )
|
||||
if ( ( ! defined( 'IMAGE_EDIT_OVERWRITE' ) || ! IMAGE_EDIT_OVERWRITE ) && $backup_sizes['full-orig']['file'] !== $basename ) {
|
||||
$tag = "full-$suffix";
|
||||
}
|
||||
} else {
|
||||
$tag = 'full-orig';
|
||||
}
|
||||
|
||||
if ( $tag )
|
||||
$backup_sizes[$tag] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $path_parts['basename']);
|
||||
|
||||
if ( $tag ) {
|
||||
$backup_sizes[$tag] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $basename );
|
||||
}
|
||||
$success = ( $path === $new_path ) || update_attached_file( $post_id, $new_path );
|
||||
|
||||
$meta['file'] = _wp_relative_upload_path( $new_path );
|
||||
|
@ -834,7 +840,7 @@ function wp_save_image( $post_id ) {
|
|||
if ( defined( 'IMAGE_EDIT_OVERWRITE' ) && IMAGE_EDIT_OVERWRITE && ! empty( $meta['sizes'] ) ) {
|
||||
foreach ( $meta['sizes'] as $size ) {
|
||||
if ( ! empty( $size['file'] ) && preg_match( '/-e[0-9]{13}-/', $size['file'] ) ) {
|
||||
$delete_file = path_join( $path_parts['dirname'], $size['file'] );
|
||||
$delete_file = path_join( $dirname, $size['file'] );
|
||||
wp_delete_file( $delete_file );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -284,13 +284,12 @@ function media_handle_upload($file_id, $post_id, $post_data = array(), $override
|
|||
if ( isset($file['error']) )
|
||||
return new WP_Error( 'upload_error', $file['error'] );
|
||||
|
||||
$name_parts = pathinfo($name);
|
||||
$name = trim( substr( $name, 0, -(1 + strlen($name_parts['extension'])) ) );
|
||||
$basename = pathinfo( $name, PATHINFO_BASENAME );
|
||||
|
||||
$url = $file['url'];
|
||||
$type = $file['type'];
|
||||
$file = $file['file'];
|
||||
$title = $name;
|
||||
$title = $basename;
|
||||
$content = '';
|
||||
$excerpt = '';
|
||||
|
||||
|
|
|
@ -346,12 +346,8 @@ abstract class WP_Image_Editor {
|
|||
}
|
||||
|
||||
if ( $filename ) {
|
||||
$ext = '';
|
||||
$info = pathinfo( $filename );
|
||||
$dir = $info['dirname'];
|
||||
|
||||
if ( isset( $info['extension'] ) )
|
||||
$ext = $info['extension'];
|
||||
$dir = pathinfo( $filename, PATHINFO_DIRNAME );
|
||||
$ext = pathinfo( $filename, PATHINFO_EXTENSION );
|
||||
|
||||
$filename = trailingslashit( $dir ) . wp_basename( $filename, ".$ext" ) . ".{$new_ext}";
|
||||
}
|
||||
|
@ -375,9 +371,8 @@ abstract class WP_Image_Editor {
|
|||
if ( ! $suffix )
|
||||
$suffix = $this->get_suffix();
|
||||
|
||||
$info = pathinfo( $this->file );
|
||||
$dir = $info['dirname'];
|
||||
$ext = $info['extension'];
|
||||
$dir = pathinfo( $this->file, PATHINFO_DIRNAME );
|
||||
$ext = pathinfo( $this->file, PATHINFO_EXTENSION );
|
||||
|
||||
$name = wp_basename( $this->file, ".$ext" );
|
||||
$new_ext = strtolower( $extension ? $extension : $ext );
|
||||
|
|
|
@ -2034,13 +2034,16 @@ function wp_unique_filename( $dir, $filename, $unique_filename_callback = null )
|
|||
$filename = sanitize_file_name($filename);
|
||||
|
||||
// Separate the filename into a name and extension.
|
||||
$info = pathinfo($filename);
|
||||
$ext = !empty($info['extension']) ? '.' . $info['extension'] : '';
|
||||
$name = basename($filename, $ext);
|
||||
$ext = pathinfo( $filename, PATHINFO_EXTENSION );
|
||||
$name = pathinfo( $filename, PATHINFO_BASENAME );
|
||||
if ( $ext ) {
|
||||
$ext = '.' . $ext;
|
||||
}
|
||||
|
||||
// Edge case: if file is named '.ext', treat as an empty name.
|
||||
if ( $name === $ext )
|
||||
if ( $name === $ext ) {
|
||||
$name = '';
|
||||
}
|
||||
|
||||
/*
|
||||
* Increment the file number until we have a unique file to save in $dir.
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.7-alpha-38293';
|
||||
$wp_version = '4.7-alpha-38294';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue