Created
November 26, 2015 15:40
-
-
Save superbiche/fac2c9742b7c1e71a8b3 to your computer and use it in GitHub Desktop.
Wordpress save_post action, that doesn't fire when autosaving.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jaredatch thank you for the reply, I was driving myself crazy over this as I just couldn't filter out the auto drafts with that code and couldn't understand why it didn't work in my environment:)