is there a way to bind some extra script to the WPSetAsThumbnail function? the function automatically inserts the image into the post’s metabox, but what if i wanted to do something else with it? could i make it alert(‘bacon’) after the thumbnail is set via ajax?
i’m trying to get a way to set the thumbnails from the quick edit screen and while i can launch the media editor, and the “set as thumbnail” does work, i can’t fade in the new image b/c i can’t figure out how to latch onto the action and grab the HTML that is passed back.
as an aside, .ajaxComplete seems to fire when i click on the Remove featured image link, but not when i click on the Set as Featured image link. is it b/c the later occurs in a thickbox that isn’t part of the original DOM?
///* edit *///
i’ve tried replicating the html more exactly. this has the problem of having multiple items with the same div ID… and still doesn’t fade in the new image either. the image is saved via ajax though and the new thumb appears on refresh.
the html markup in my post column:
<div id="postimagediv"><div class="inside"><p class="hide-if-no-js"><a title="Set featured image" href="'.admin_url( 'media-upload.php?post_id='.$post_id.'&type=image&TB_iframe=1&width=640&height=397')" id="set-post-thumbnail" class="thickbox">'.get_the_post_thumbnail($post_id, array(35,35))
i’d still like some way to latch onto the jquery event so that i can do my own script, but i’m starting to believe this is impossible. i liked the idea of using ajaxComplete but i can’t get that to run based on an action that occurs in the media thickbox.
Yes, on your 2nd question 🙂
From what I saw in set-post-thumbnail.dev.js, it appears that you only need to add a link/anchor with the
wp-post-thumbnail
class on it in your quick edit screen.And you will get the image faded inside that link when the ajax request completes.
For alerting “bacon” after the ajax completes, this might work:
The ajaxComplete approach:
You might need to check which ajax request this is, do console.logs for all arguments and search of the property that holds the ajax action name, which should be “set_post_thumbnail” or something…
Answering to this:
If we do this, instead of bacon, we close the ThickBox window 🙂
Check this Q&A for more details:
How to Reload the Dashboard After Clicking Update in Quick-Edit?
In the end I found that I could not bind or trigger this action. I had to duplicate it as follows with the javascript and then an ajax callback.
Javascript:
Ajax Callback: