• I’m using following code to force WordPress page to save post as draft, is there any callback function for it, I want to alert a text after it complete saving post as draft.

    if ( wp.autosave.server ) {
    wp.autosave.server.triggerSave();
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    No, there’s nothing you could hook into. AFAICT you cannot even verify the save was successful, triggering the save doesn’t return anything. You could just add more code to what you have to display confirmation, but it’s only conjecture since you cannot actually verify success.

    I believe to save a draft in a way where you can confirm success would require sending some sort of AJAX POST request that saves a draft post and returns a success or fail message after which you can display an appropriate message. This can be done either as a custom AJAX routine or by using the WP REST API. Either one is more involved than what you have now.

    Thread Starter Aumkar Thakur

    (@aumkar)

    There is always a solution, if WordPress can do this so am I, whenever anything is auto save the text at bottom right of editor change to “Saving…” and after it complete saving the post the text become “Saved on 01/01/01” So I looked in the source code and inside load-script.php I found that there is a callback which runs after WordPress complete saving the post and following is the code.

    jQuery(document).on('heartbeat-tick.autosave', function( event, data ) {
    //your code here
    }):

    Add it using metabox to any page and whenever post is auto-saved it will run your code.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Callback for wp.autosave.server.triggerSave();’ is closed to new replies.