WordPress.org

Ready to get started?Download WordPress

Forums

Hooking into the new Media Manager window (2 posts)

  1. Doug
    Member
    Posted 1 year ago #

    On several themes I build, I need to have fields that take an attachment id, and can be populated by using the media uploader and "inserting" the selected media. I have a decent solution for the moment that does the trick, but now that we have this new Media Manager, I was wondering if there's a way to hook into it?

    I've tried adding custom .insert-media links with the data-editor attribute set to the id of a normal text field, but I can't seem to get it to work; It just get's inserted into the mceEditor.

    The closest I've gotten is to have the click recreate the window.send_to_editor function, and have it unset itself when it's done. But, I don't know how to detect when the media manager is closed without inserting anything and have it unset itself then too.

    function setup_send_to_editor(e){
    	e.preventDefault();
    	//Temporarily assign a function to window.send_to_editor
    	window.send_to_editor = function(h){
    		//Do stuff
    		window.send_to_editor = false;
    	}
    }
    jQuery(document).ready(function($){
    	$('body').on('click', '.custom-insert-media', setup_send_to_editor);
    });

    UPDATE

    Actually, I can fix that last issue by just adding a click even to the normal .insert-media button so it clears before loading the media manager for a post. Still, I'm hoping there's a cleaner way of hooking into the manager, for setting up stuff like additional post thumbnail type metaboxes or a section to add multiple images for the purpose of a carousel; separate from the content.

  2. Blood Angel
    Member
    Posted 1 year ago #

    I am also currently looking into this issue.

    Wondering, that data-editor does not seem to have any effect.

Topic Closed

This topic has been closed to new replies.

About this Topic