I want to create a new user when a post is created from the back end. Is there a WP Hook that calls before a post is created. Thanks
-
Hi Saud. See my answer for one possibility - it might be useful to provide info on why you need to call the book immediately before the post is created. E.g. do you want the new user to own the post?– mozbozJul 3, 2020 at 12:57
-
1I have a custom post type of agent. My requirement is that when i create a agent from back-end, a new user should be registered with the agent info. I can do this with save_post hook but i want a hook that fires before a post is created because first i want to check if the agent info entered exists or not. if exists than post should not be created– Saud BinsaeedJul 3, 2020 at 13:10
2 Answers
There's a hook save_post
, docs here: https://developer.wordpress.org/reference/hooks/save_post/ which will allow you to run some code after the post is saved. Example from there:
function add_user_after_post_save( $post_id ) {
// add a user?
// move the post to the user?
}
add_action( 'save_post', 'add_user_after_post_save' );
Not sure why you'd need to call the hook immediately before the post is created, as anything that you can do then you can also do in the save_post hook, but please provide more information.
-
save_post hook calls after a post is created. i want a hook that fires before a post is created. Jul 3, 2020 at 13:05
Ik think you can use: wp_insert_post_data
According to the codex: A filter hook called by the wp_insert_post function prior to inserting into or updating the database.
https://codex.wordpress.org/Plugin_API/Filter_Reference/wp_insert_post_data