Is there a standard way to listen for an on change event of a posts featured image

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!

Read more here:: Is there a standard way to listen for an on change event of a posts featured image

Leave a Reply

Your email address will not be published. Required fields are marked *