WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#32899 closed enhancement (worksforme)

Ability to extend Attachment Display Settings section

Reported by: paulschreiber Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.2.2
Component: Media Keywords:
Focuses: Cc:
PR Number:

Description

It would be very helpful if WordPress let you easily extend the Attachment Display Settings section.

Currently, if you extend wp.media.view.Attachment.Details, your render() call gets access to this.$el, something like

<div tabindex="0" data-id="75099" class="attachment-details save-ready">
...

However, the DOM doesn't yet contain the attachment settings, i.e.

<div class="attachment-display-settings">
<h3>Attachment Display Settings</h3>
...

I had to use a crappy workaround like this:

setTimeout(function() {
  jQuery('.attachment-display-settings').append( wp.media.template('my-attachment-display-settings')({}) );
  }, 200);

It would be very helpful if there was an easy way to extend the display settings section. One such way could be to fire an event after the render completes.

Change History (6)

#1 follow-up: @wonderboymusic
4 years ago

  • Keywords close added

have you tried 'attachment_fields_to_edit'?

#2 in reply to: ↑ 1 @swissspidy
4 years ago

  • Keywords reporter-feedback added

@paulschreiber Have you tried using 'attachment_fields_to_edit' as suggested?

#3 @paulschreiber
4 years ago

Yes, I eventually used attachment_fields_to_edit. It worked. However, that adds metadata to the database that persists with the image. I wanted something on the view layer only.

#4 @swissspidy
4 years ago

  • Keywords close reporter-feedback removed
  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

If saving that metadata to the database is not desired, one could probably hook into the appropriate save_ action to unset the metadata.

#5 @paulschreiber
4 years ago

Even if that did work, it would be hacky and cause unnecessary database calls.

I want this to act like other display settings (size, alignment, link to).

#6 @valendesigns
4 years ago

@paulschreiber You could also extend wp.media.view.Settings.AttachmentDisplay to replace the template.

_.extend( wp.media.view.Settings.AttachmentDisplay.prototype, {
	template: wp.template( 'my-attachment-display-settings' )
});
Note: See TracTickets for help on using tickets.