Make WordPress Core

Opened 10 years ago

Closed 9 years ago

Last modified 9 years ago

#32531 closed defect (bug) (fixed)

Media library filename based on GUID prevents embedding

Reported by: daxelrod's profile daxelrod Owned by: wonderboymusic's profile wonderboymusic
Milestone: 4.3 Priority: normal
Severity: normal Version: 4.1
Component: Media Keywords: has-patch
Focuses: ui, administration Cc:

Description

The "Add Media" modal on posts is dependent on GUID matching the actual filename to allow embedding of audio and video media attachments. The "Attachment Display Settings" pane provides options for "Embed or Link" or "Link To" depending on canEmbed. But if the GUID is a permalink (example.com/?attachment_id=XXX) instead of an actual filepath (example.com/wp-content/wp-uploads/file.mp3), the audio or media element cannot be embedded in a post via the admin UI - only the "Link To" options will be presented.

wp.media.controller.Library.canEmbed checks for attachment type "audio" or "video" and also checks the filename for a specific extension:

return _.contains( wp.media.view.settings.embedExts, attachment.get('filename').split('.').pop() );

If given an actual filename, the function performs as expected. But provided with a permalink, it fails and the attachment cannot be embedded.

Imported media especially has this issue because of how GUIDs are automatically assigned in wp_insert_post():

	// Set GUID.
	if ( ! $update && '' == $current_guid ) {
		$wpdb->update( $wpdb->posts, array( 'guid' => get_permalink( $post_ID ) ), $where );
	}

Fixing this has a side benefit of making the attachment title (filename) in the media library more accurate as well.

Attachments (1)

media_filename.patch (623 bytes) - added by daxelrod 10 years ago.
Patch to replace GUID with attachment filename

Download all attachments as: .zip

Change History (5)

@daxelrod
10 years ago

Patch to replace GUID with attachment filename

#1 @daxelrod
10 years ago

  • Keywords has-patch added

Attached patch which attacks this from wp_prepare_attachment_for_js(). Replaced $attachment->guid with get_attached_file( $attachment->ID ).

#2 @wonderboymusic
9 years ago

  • Milestone changed from Awaiting Review to 4.3

#3 @wonderboymusic
9 years ago

  • Owner set to wonderboymusic
  • Resolution set to fixed
  • Status changed from new to closed

In 32914:

In wp_prepare_attachment_for_js(), when setting filename, call wp_basename() on the result of get_attached_file(), not WP_Post->guid. guid can be set to the result get_permalink(), which is not a file path.

Props daxelrod.
Fixes #32531.

This ticket was mentioned in Slack in #core by rmccue. View the logs.


9 years ago

Note: See TracTickets for help on using tickets.