Working on a project where I would like to have buttons within the actual visual editor area where the user can click on the placeholder image and it brings up the upload dialog.
I’ve seen that people create their own buttons that adds boxes that the user then should select with their mouse and then click the add media upload. To me that seems like it’s bound for a bad user experience. Thus I’m looking to see if someone have seen a plugin that does this.
Imaging that you could actually click “insert image here” and have an upload dialog brought up.
While I agree with Tom, there still an be a general answer that explains the general concept and the parts that aren’t moving.
The PHP plugin to set the default content
First there has to be some default content. And there’s a filter for that:
TinyMCE JS events
Then you simply need to add an event listener. Example from the official documentation.
The global WordPress
wp
objectFinally, you just need to attach the media open dialog action to the content itself. There’s the
wp
object, that holds most of WordPress core js stuff. Just typewp
into your console and you’ll see that you have global access after the DOM is ready to the following:Object
function ( options )
Object
Object
Heartbeat
Object
function ( attributes )
function ( options )
function
As you can see, there’s
media
andBackbone
as well. Just hitwp.media.
into your (for e.g.) Chrome dev tools console and you’ll see the autocomplete function telling what’s available. Additionally to that, Dominik Schilling, the author of the media library has a nice set of demos for the WP Media library on GitHub.