Guest User

Untitled

a guest
Aug 17th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. <?php
  2. // wp-includes/post.php で定義されている wp_transition_post_status 関数
  3.  
  4. /**
  5. * Fires actions related to the transitioning of a post's status.
  6. *
  7. * When a post is saved, the post status is "transitioned" from one status to another,
  8. * though this does not always mean the status has actually changed before and after
  9. * the save. This function fires a number of action hooks related to that transition:
  10. * the generic {@see 'transition_post_status'} action, as well as the dynamic hooks
  11. * {@see '$old_status_to_$new_status'} and {@see '$new_status_$post->post_type'}. Note
  12. * that the function does not transition the post object in the database.
  13. *
  14. * For instance: When publishing a post for the first time, the post status may transition
  15. * from 'draft' – or some other status – to 'publish'. However, if a post is already
  16. * published and is simply being updated, the "old" and "new" statuses may both be 'publish'
  17. * before and after the transition.
  18. *
  19. * @since 2.3.0
  20. *
  21. * @param string $new_status Transition to this post status.
  22. * @param string $old_status Previous post status.
  23. * @param WP_Post $post Post data.
  24. */
  25. function wp_transition_post_status( $new_status, $old_status, $post ) {
  26. /**
  27. * Fires when a post is transitioned from one status to another.
  28. *
  29. * @since 2.3.0
  30. *
  31. * @param string $new_status New post status.
  32. * @param string $old_status Old post status.
  33. * @param WP_Post $post Post object.
  34. */
  35. do_action( 'transition_post_status', $new_status, $old_status, $post );
  36.  
  37. /**
  38. * Fires when a post is transitioned from one status to another.
  39. *
  40. * The dynamic portions of the hook name, `$new_status` and `$old status`,
  41. * refer to the old and new post statuses, respectively.
  42. *
  43. * @since 2.3.0
  44. *
  45. * @param WP_Post $post Post object.
  46. */
  47. do_action( "{$old_status}_to_{$new_status}", $post );
  48.  
  49. /**
  50. * Fires when a post is transitioned from one status to another.
  51. *
  52. * The dynamic portions of the hook name, `$new_status` and `$post->post_type`,
  53. * refer to the new post status and post type, respectively.
  54. *
  55. * Please note: When this action is hooked using a particular post status (like
  56. * 'publish', as `publish_{$post->post_type}`), it will fire both when a post is
  57. * first transitioned to that status from something else, as well as upon
  58. * subsequent post updates (old and new status are both the same).
  59. *
  60. * Therefore, if you are looking to only fire a callback when a post is first
  61. * transitioned to a status, use the {@see 'transition_post_status'} hook instead.
  62. *
  63. * @since 2.3.0
  64. *
  65. * @param int $post_id Post ID.
  66. * @param WP_Post $post Post object.
  67. */
  68. do_action( "{$new_status}_{$post->post_type}", $post->ID, $post );
  69. }
Add Comment
Please, Sign In to add comment