I would like to collect main info about post like Title etc. in moment when post was written and it’s going to be published and perform some actions on this data. What’s the hook for that?
Thanks!
I would like to collect main info about post like Title etc. in moment when post was written and it’s going to be published and perform some actions on this data. What’s the hook for that?
Thanks!
You must be logged in to post a comment.
The function is
wp_insert_post()
, and as you can see there are some hooks you can use to modify data.wp_insert_post_data
is a filter that gets all data right before it will be inserted into the database, so you modify it there and don’t need to do anything to get it saved. At the end of the function you can see thesave_post
action and its equivalentwp_insert_post
, which are more appropriate if you want to do something (instead of change something).These functions are fired when a post is saved, not only when it is published. For the publish action, look at
wp_transition_post_status()
, which has three hooks:transition_post_status
, called with the new and old statuses, and the post data{$old_status}_to_{$new_status}
, likedraft_to_publish
, called with the post data{$new_status}_{$post->post_type}
, likepublish_page
, called with the post ID and post dataAlso check here: WordPress prompt checklist before publish? “WordPress prompt checklist before publish?”