Advertisement
5ally

save_post && DOING_AUTOSAVE

Jan 31st, 2019
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.69 KB | None | 0 0
  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. } );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement