Site icon Dhanendran's Blog

WordPress: Post/Page creation workflow

Developing WordPress site for client or your own site?

Then you should know the basic workflow of Post/Page creation hooks. Okay! Let’s get started with the hooks.

What is hooks?

Hooks are just a functions, which will help us to do some actions or tasks when something is happen. Say for example, we can trigger an email when a new post/page is published or updated or deleted.

Post and Page create/update/delete hooks

  1. wp_insert_post_data
  2. save_post_{post_type}
  3. save_post
  4. wp_insert_post
  5. pre_post_update
  6. post_updated
  7. publish_post
  8. publish_page
  9. publish_future_post
  10. updated_postmeta
  11. wp_trash_post
  12. untrash_post
  13. before_delete_post
  14. delete_post
  15. deleted_post

wp_insert_post_data

wp_insert_post_data is a filter hook, which will run before the post/page is being saved into the database. Here we can modify the post/page data if needed.

save_post_{post_type}

save_post_{post_type} action runs after the post/page has been saved into the database.

save_post

save_post action is called right after the post/page has been saved on the database. It can be a new post/page save or existing post/page update. save_post action will be called with post ID, post object and a boolean value for update or new post.

wp_insert_post

wp_insert_post action is called after the post/page has been saved or updated. We can able to make it run only for the new post using the $update parameter.

pre_post_update

pre_post_update action runs just before a post or page is updated. Action function called with post or page ID.

post_updated

post_updated action runs after a post or page is updated. Action function arguments: post or page ID, WP_Post object of the post before the update and after the update.

publish_post

publish_post action runs when a post is published, or if it is edited and its status is changed to “published”.  Action function arguments: post ID, post object.

publish_page

publish_page action runs when a page is published, or if it is edited and its status is changed to “published”. Action function arguments: post ID, post object.

publish_future_post

publish_future_post action runs when a future post or page is published. Action function arguments: post ID.

updated_postmeta

updated_postmeta action runs when a metadata has been updated.

wp_trash_post

wp_trash_post action runs when a post or page is about to be trashed. Action function arguments: post or page ID.

untrash_post

untrash_post action  runs just before undeletion, when a post or page is restored. Action function arguments: post or page ID.

before_delete_post

before_delete_post action runs when a post or page is about to be deleted. Comments, attachments and metadata are still available. Action function arguments: post or page ID.

delete_post

delete_post action runs when a post or page is about to be deleted. Comments, attachments and metadata are already deleted. Action function arguments: post or page ID.

deleted_post

deleted_post action runs when a post or page is deleted.

Exit mobile version