1

I'm working on an artist plugin which lets you upload/create a depth map image for jpg's in your media library.

To do this, I created a custom meta box which lets you draw the depth map using canvas/js, on the post edit page.

However in order to see what you're doing, you need to be able to draw ontop of the featured image your making the depth map for.

I can get the posts current featured image according to the database, but if the user changes the image without clicking update, and then goes on to create a depth map I would load up the old image.

I know I can ask people to update the post to work with the new image, but that feels slow and yucky.

So I thought I would use JS to find out what picture is currently in the featured image box and just listen for it to change.

However I realize between wordpress 4.x and 5.0 some big changes were made to the editor and all the html/tags surrounding the featured image are different.

I could write use case logic for both of these, but this is starting to feel like a serious hack, and I'm not even sure how compatible it would be with other plugins/versions of wordpress I don't test it on.

Is there any standard way in wordpress to listen for a change to that image, like maybe listen to the wp.media object somehow?

Any help would be much appreciated!

Edit:

I found a git hub conversation about this exact topic. Turns out before Gutenberg you could use this code to log every media event in the console.log

wp.media.frame.on('all', function(e) { console.log(e); });

Unfortunately with Gutenberg that is no longer possible. Still looking for a way that works with both.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.