From 577fea566a98e05fc30d045f0e3f5334a074622e Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Tue, 15 Sep 2015 02:49:12 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@34163 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/async-upload.php | 5 ++++- src/wp-admin/custom-header.php | 2 +- src/wp-admin/includes/ajax-actions.php | 2 +- src/wp-admin/includes/class-wp-media-list-table.php | 8 +++++++- src/wp-admin/includes/class-wp-site-icon.php | 2 +- src/wp-admin/includes/media.php | 3 ++- src/wp-includes/media.php | 5 +++-- src/wp-includes/post-functions.php | 5 +++-- 8 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/wp-admin/async-upload.php b/src/wp-admin/async-upload.php index 9dda8ae190..0a3c420845 100644 --- a/src/wp-admin/async-upload.php +++ b/src/wp-admin/async-upload.php @@ -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 ''; echo '' . _x( 'Edit', 'media item' ) . ''; - $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 '
' . esc_html( wp_html_excerpt( $title, 60, '…' ) ) . '
'; break; case 2 : diff --git a/src/wp-admin/custom-header.php b/src/wp-admin/custom-header.php index ba9bb72dd4..1b2ac2e281 100644 --- a/src/wp-admin/custom-header.php +++ b/src/wp-admin/custom-header.php @@ -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 ); diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php index 26a6bf9b23..1d527aaf1a 100644 --- a/src/wp-admin/includes/ajax-actions.php +++ b/src/wp-admin/includes/ajax-actions.php @@ -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 ); diff --git a/src/wp-admin/includes/class-wp-media-list-table.php b/src/wp-admin/includes/class-wp-media-list-table.php index ef84bd75f7..8482e3304e 100644 --- a/src/wp-admin/includes/class-wp-media-list-table.php +++ b/src/wp-admin/includes/class-wp-media-list-table.php @@ -370,7 +370,13 @@ class WP_Media_List_Table extends WP_List_Table { -

guid ); ?>

+

+ + ID ); + echo wp_basename( $file ); + ?> +

guid; + $parent_url = wp_get_attachment_url( $parent->ID ); $url = str_replace( basename( $parent_url ), basename( $cropped ), $parent_url ); $size = @getimagesize( $cropped ); diff --git a/src/wp-admin/includes/media.php b/src/wp-admin/includes/media.php index 237f3e62d7..a12f6507d0 100644 --- a/src/wp-admin/includes/media.php +++ b/src/wp-admin/includes/media.php @@ -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(); diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index 2e8d7a3010..4dfefd4398 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -1175,7 +1175,7 @@ function wp_underscore_playlist_templates() { <# } #>
- @@ -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'); diff --git a/src/wp-includes/post-functions.php b/src/wp-includes/post-functions.php index 820b6a078d..fb5f84daeb 100644 --- a/src/wp-includes/post-functions.php +++ b/src/wp-includes/post-functions.php @@ -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 ) )