Is there a hook for the popup window which shows up when you click on the edit button on an image in a post?
Leave a Reply
You must be logged in to post a comment.
Is there a hook for the popup window which shows up when you click on the edit button on an image in a post?
You must be logged in to post a comment.
The answer is there is no damn hook for the edit button.
It’s just a bunch of JS contained within
wp-includes/js/tinymce/plugins/wpeditimage/plugin.js
.I’ve included the barebones of what you need below. Key points:
a. Clicking an element with a
data-wp-imgselect
attribute will open the image edit dialogue. You need to change that to something else if you don’t want that to happen (data-wp-chartselect
in my example).b. A good way of preventing
wpeditimage
from conflicting is to give whatever element you’re editing amceItem
class. This will make WordPress think it’s a placeholder and thus not select it.c. The bit you can’t see is my Angular app loaded from the
datacharts.cb_url
global. I have a button in that which does the following when clicked:The key thing here is that it creates an image with a data attribute (
data-llama
) containing a Base64-encoded representation of my chart configuration. This is decoded and deserialised when it gets passed back to my Angular app via TinyMCE, which is then used to populate the chart. I’m open-sourcing my entire codebase and will link to it here once I’ve done so, in case you want to see a complete implementation.Without any further ado, here’s my TinyMCE plugin: