set thumbnails from edit screen (quick edit?)

  1. helgatheviking

    I've been able to modify the posts screen (wp-admin/edit.php) to add a column for thumbnails. I've also been able to set a link such that it launches the media uploaded and it turns out that the 'set as featured' does actually set the thumbnail. However, b/c there is no trigger or hook or something in the WPSetAsThumbnail function I can't tell it to immediately display the image on the screen until I refresh.

    the WPSetAsThumbnail function (if successful at uploading) will trigger win.WPSetThumbnailHTML(str); which is responsible for loading the image dynamically in the featured image meta box. however this function is pre-defined by jquery selectors that won't work well on the posts screen w/ multiple posts and columns.

    i'd say we need an action hook to hook into on successful completion, but i don't know what the jquery/javascript equivalent of that is.

    .trigger() ?

    Posted: 6 years ago #
  2. shazdeh

    You mean callbacks?

    Posted: 6 years ago #
  3. helgatheviking

    maybe? i'm decent in scripting, but not a ninja or anything. from what i can tell in the jquery API trigger() might work too.... say the trigger is in the set-post-thumbnail.js file?

    function WPSetAsThumbnail(id, nonce){
    	var $link = jQuery('a#wp-post-thumbnail-' + id);
    	$link.text( setPostThumbnailL10n.saving );
    	jQuery.post(ajaxurl, {
    		action:"set-post-thumbnail", post_id: post_id, thumbnail_id: id, _ajax_nonce: nonce, cookie: encodeURIComponent(document.cookie)
    	}, function(str){
    		var win = window.dialogArguments || opener || parent || top;
    		$link.text( setPostThumbnailL10n.setThumbnail );
    		if ( str == '0' ) {
    			alert( setPostThumbnailL10n.error );
    		} else {
    			$link.text( setPostThumbnailL10n.done );
    			$link.fadeOut( 2000 );
    			/*HACK*/	win.trigger("WPCompleteSetasThumbnail", [ id, str ]); /*end*/

    then in my own code i could bind to that custom event? obviously i wouldn't alert this, but just for hypothetical

    $('#foo').bind('WPCompleteSetasThumbnail', function() {
      alert('User set thumbnail');
    Posted: 6 years ago #
  4. helgatheviking

    so my attempt at using bind failed pretty miserably. instead of #foo i used the body tag, but nothing alerted when the thumbnail was set. is that possibly b/c my script is on a wp-admin/post.php? page while the set as thumbnail link is clicked in the thickbox?

    could you elaborate on what you mean by callback? i don't know if my scripting vocab is good enough to make a really good suggestion

    Posted: 6 years ago #
  5. Ipstenu (Mika Epstein)

    helgatheviking - This is for pitching ideas for core, not bashing out your code. Please post this in the main support forums if you want help with the code to make this happen, or join the wp-hackers list.

    Posted: 6 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.

  • Rating

    0 Votes
  • Status

    Sorry, not right now