SHARE
TWEET

save_post && DOING_AUTOSAVE

5ally Jan 31st, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. // Example 1: Cancel the action if WordPress is doing autosave.
  3. add_action( 'save_post', function( $post_id ){
  4.     if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { // WordPress is doing autosave.
  5.         return; // cancel your action
  6.     }
  7.  
  8.     //...your action here...
  9. } );
  10.  
  11. // Example 2: Cancel the action if WordPress is doing autosave and that the
  12. // post has been successfully autosaved...
  13. add_action( 'save_post', function( $post_id ){
  14.     if (
  15.         ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) && // WordPress is doing autosave
  16.         wp_is_post_autosave( $post_id )                      // and the autosave succeeded.
  17.     ) {
  18.         return; // cancel your action
  19.     }
  20.  
  21.     //...your action here...
  22. } );
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top