Skip to content

Instantly share code, notes, and snippets.

@superbiche
Created November 26, 2015 15:40
Show Gist options
  • Select an option

  • Save superbiche/fac2c9742b7c1e71a8b3 to your computer and use it in GitHub Desktop.

Select an option

Save superbiche/fac2c9742b7c1e71a8b3 to your computer and use it in GitHub Desktop.

Revisions

  1. superbiche created this gist Nov 26, 2015.
    23 changes: 23 additions & 0 deletions wp-autosave-not-draft.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    add_action('save_post', 'my_post_saved');

    function my_post_saved($post_id, $post) {
    if (isset($post->post_status) && 'auto-draft' == $post->post_status) {
    return;
    }

    // Autosave, do nothing
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
    return;
    }
    // AJAX? Not used here
    if (defined('DOING_AJAX') && DOING_AJAX) {
    return;
    }

    // Return if it's a post revision
    if ( false !== wp_is_post_revision( $post_id ) ) {
    return;
    }

    // Do what you want
    }