Guest User

Untitled

a guest
Jun 22nd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. <?php
  2. // called when saving a post.
  3.  
  4. public function tl_save_post($post_id){
  5.  
  6. // dont do this on auosave.
  7. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
  8. return;
  9.  
  10. // verify this came from the our screen and with proper authorization,
  11. // because save_post can be triggered at other times
  12.  
  13.  
  14. $post = get_post($post_id);
  15.  
  16. if (!isset($post->post_type) || 'my_post_type' != $post->post_type ) {
  17. return;
  18. }
  19.  
  20. // unhook this function so it doesn't loop infinitely
  21. remove_action( 'save_post', 'tl_save_post, 100 );
  22.  
  23. // do stuff that might trigger another Save
  24.  
  25. /* stuff here */
  26.  
  27. // put back the hook
  28. add_action( 'save_post', 'tl_save_post, 100 );
  29. }
  30.  
  31. add_action( 'save_post', 'tl_save_post, 100 );
Add Comment
Please, Sign In to add comment