Media Manager once again.
This time I’m looking for a simple hack/hook/filter to change default “Attachment Display Settings” from media manager. The option is “Link To” that is default set to “Media File” and I would like to force it for all users to be default set to “none”.
If there is no way to do it with hook/filter (media-template.php lines 282 – 306) – is there a way to attach jQuery file to Media Manager and use it to force change option after Media Manager is loaded?
You can do what you want by overriding appropriate Backbone view, which is responsible for rendering attachments display settings form.
plugin.php
add_action( 'load-post.php', 'wpse8170_media_popup_init' );
add_action( 'load-post-new.php', 'wpse8170_media_popup_init' );
function wpse8170_media_popup_init() {
wp_enqueue_script( 'wpse8170-media-manager', plugins_url( '/js/media.js', __FILE__ ), array( 'media-editor' ) );
}
media.js
(function() {
var _AttachmentDisplay = wp.media.view.Settings.AttachmentDisplay;
wp.media.view.Settings.AttachmentDisplay = _AttachmentDisplay.extend({
render: function() {
_AttachmentDisplay.prototype.render.apply(this, arguments);
this.$el.find('select.link-to').val('none');
this.model.set('link', 'none');
this.updateLinkTo();
}
});
})();