0

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

2
  • 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?
    – mozboz
    Jul 3, 2020 at 12:57
  • 1
    I 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 Jul 3, 2020 at 13:10

2 Answers 2

0

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.

1
  • 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
0

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

1
  • I think this might help. Thanks for your help :) Jul 3, 2020 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.