superbiche
11/26/2015 - 3:40 PM

Wordpress save_post action, that doesn't fire when autosaving.

Wordpress save_post action, that doesn't fire when autosaving.

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
}