Make WordPress Core

Opened 8 years ago

Last modified 8 years ago

#40869 new enhancement

Replacing an image in content editor

Reported by: macpresss's profile MacPresss Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7.5
Component: Media Keywords:
Focuses: ui Cc:

Description

Hello,

I noticed a strange behaviour in WordPress User Experience while dealing with images.

Let's say for example you want to replace an existing image in the content editor while creating or editing a post/page. Right now this is only possible when this 'existing' image is part of your Media Library and probably has an attachment post_id.

What about people that have added images from external urls or maybe even placeholder images that have been adding to their content via custom TinyMCE buttons. When you press Edit on those images you can't easily replace them for an image inside your Media Library.

I think this is a little odd and we should be able to replace any image in our editor for one inside our library so I made this little change what will make the 'Replace' button always show up in the Image Details modal.

/wp-includes/media-template.php :line: 885

<div class="image">
	<img src="{{ data.model.url }}" draggable="false" alt="" />

	<# if ( data.attachment && window.imageEdit ) { #>
		<div class="actions">
			<input type="button" class="edit-attachment button" value="<?php esc_attr_e( 'Edit Original' ); ?>" />
			<input type="button" class="replace-attachment button" value="<?php esc_attr_e( 'Replace' ); ?>" />
		</div>
	<# else if ( data.attachment && window.imageEdit ) { #>
		<div class="actions">
			<input type="button" class="replace-attachment button" value="<?php esc_attr_e( 'Replace' ); ?>" />
		</div>
	<# } #>
</div>

Todo.
While adding a new image to the editor we get a small JavaScript error.

Attachments (1)

media-template.php (45.1 KB) - added by MacPresss 8 years ago.

Download all attachments as: .zip

Change History (2)

#1 @swissspidy
8 years ago

Hey there,

Welcome to Trac and thanks for your contribution!

Would you mind creating a proper patch file for this change so we can have a diff of all the changes?

See https://make.wordpress.org/core/handbook/tutorials/working-with-patches/ for help.

Note: See TracTickets for help on using tickets.