[resolved] Losing custom plugin data when restoring autosave (2 posts)

  1. tonnaer
    Posted 3 years ago #

    I have a problem similar to the ones described in these posts:

    I solved it partly by adding the check for autosave in the function I call in the save_post hook:

    function my_function($pID) {
      // if the function is called by the WP autosave feature, nothing must be saved
      if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
      $text = (isset($_POST['textfield1'])) ? $_POST['textfield1'] : '';
      update_post_meta($pID, '_textfield1', $text);
      $text = (isset($_POST['textfield2'])) ? $_POST['textfield2'] : '';
      update_post_meta($pID, '_textfield2', $text);
    add_action('save_post', 'my_function');

    Now if I leave the edit post screen without updating after a draft has been saved, and then I reenter the edit post screen, my custom plugin data is still there.

    But, if I decide to restore the saved draft, my plugin's text fields are empty, all data lost.

    What am I missing? How can I prevend the loss of my plugin data?

  2. tonnaer
    Posted 3 years ago #

    After a couple of hours of searching, I seem to have found the answer.
    I've added the nonce field verification (as in the example on this codex page: http://codex.wordpress.org/Function_Reference/add_meta_box) and now the values don't disappear when I restore an autosave.

Topic Closed

This topic has been closed to new replies.

About this Topic