Don't ever use the `guid` value when retrieving URLs for media, use `wp_get_attachment_url()`. Use `get_attached_file()` for path to file.

Fixes #33386.

Built from https://develop.svn.wordpress.org/trunk@34163


git-svn-id: http://core.svn.wordpress.org/trunk@34131 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2015-09-15 02:50:25 +00:00
parent d7d5789088
commit 191400f9e6
9 changed files with 23 additions and 11 deletions

View File

@ -62,7 +62,10 @@ if ( isset($_REQUEST['attachment_id']) && ($id = intval($_REQUEST['attachment_id
if ( $thumb_url = wp_get_attachment_image_src( $id, 'thumbnail', true ) )
echo '<img class="pinkynail" src="' . esc_url( $thumb_url[0] ) . '" alt="" />';
echo '<a class="edit-attachment" href="' . esc_url( get_edit_post_link( $id ) ) . '" target="_blank">' . _x( 'Edit', 'media item' ) . '</a>';
$title = $post->post_title ? $post->post_title : wp_basename( $post->guid ); // Title shouldn't ever be empty, but use filename just in case.
// Title shouldn't ever be empty, but use filename just in case.
$file = get_attached_file( $post->ID );
$title = $post->post_title ? $post->post_title : wp_basename( $file );
echo '<div class="filename new"><span class="title">' . esc_html( wp_html_excerpt( $title, 60, '&hellip;' ) ) . '</span></div>';
break;
case 2 :

View File

@ -1116,7 +1116,7 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?>
*/
final public function create_attachment_object( $cropped, $parent_attachment_id ) {
$parent = get_post( $parent_attachment_id );
$parent_url = $parent->guid;
$parent_url = wp_get_attachment_url( $parent->ID );
$url = str_replace( basename( $parent_url ), basename( $cropped ), $parent_url );
$size = @getimagesize( $cropped );

View File

@ -3155,7 +3155,7 @@ function wp_ajax_crop_image() {
/** This filter is documented in wp-admin/custom-header.php */
$cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication.
$parent_url = get_post( $attachment_id )->guid;
$parent_url = wp_get_attachment_url( $attachment_id );
$url = str_replace( basename( $parent_url ), basename( $cropped ), $parent_url );
$size = @getimagesize( $cropped );

View File

@ -370,7 +370,13 @@ class WP_Media_List_Table extends WP_List_Table {
<?php echo $link_end; ?>
<?php _media_states( $post ); ?>
</strong>
<p class="filename"><span class="screen-reader-text"><?php _e( 'File name:' ); ?> </span><?php echo wp_basename( $post->guid ); ?></p>
<p class="filename">
<span class="screen-reader-text"><?php _e( 'File name:' ); ?> </span>
<?php
$file = get_attached_file( $post->ID );
echo wp_basename( $file );
?>
</p>
<?php
}

View File

@ -80,7 +80,7 @@ class WP_Site_Icon {
*/
public function create_attachment_object( $cropped, $parent_attachment_id ) {
$parent = get_post( $parent_attachment_id );
$parent_url = $parent->guid;
$parent_url = wp_get_attachment_url( $parent->ID );
$url = str_replace( basename( $parent_url ), basename( $cropped ), $parent_url );
$size = @getimagesize( $cropped );

View File

@ -1368,7 +1368,8 @@ function get_media_item( $attachment_id, $args = null ) {
$toggle_on = __( 'Show' );
$toggle_off = __( 'Hide' );
$filename = esc_html( wp_basename( $post->guid ) );
$file = get_attached_file( $post->ID );
$filename = esc_html( wp_basename( $file ) );
$title = esc_attr( $post->post_title );
$post_mime_types = get_post_mime_types();

View File

@ -1175,7 +1175,7 @@ function wp_underscore_playlist_templates() {
<img src="{{ data.thumb.src }}"/>
<# } #>
<div class="wp-playlist-caption">
<span class="wp-playlist-item-meta wp-playlist-item-title"><?php
<span class="wp-playlist-item-meta wp-playlist-item-title"><?php
/* translators: playlist item title */
printf( _x( '&#8220;%s&#8221;', 'playlist item title' ), '{{ data.title }}' );
?></span>
@ -2076,7 +2076,8 @@ function get_attachment_taxonomies( $attachment ) {
if ( ! is_object($attachment) )
return array();
$filename = basename($attachment->guid);
$file = get_attached_file( $attachment->ID );
$filename = basename( $file );
$objects = array('attachment');

View File

@ -4648,7 +4648,7 @@ function wp_delete_attachment( $post_id, $force_delete = false ) {
foreach ( $comment_ids as $comment_id ) {
wp_delete_comment( $comment_id, true );
}
wp_defer_comment_counting( false );
$post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $post_id ));
@ -4974,7 +4974,8 @@ function wp_mime_type_icon( $mime = 0 ) {
$mime = (int) $mime;
if ( $post = get_post( $mime ) ) {
$post_id = (int) $post->ID;
$ext = preg_replace('/^.+?\.([^.]+)$/', '$1', $post->guid);
$file = get_attached_file( $post_id );
$ext = preg_replace('/^.+?\.([^.]+)$/', '$1', $file);
if ( !empty($ext) ) {
$post_mimes[] = $ext;
if ( $ext_type = wp_ext2type( $ext ) )

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.4-alpha-34162';
$wp_version = '4.4-alpha-34163';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.