There’s a hook called user_register()
that you could use. It happens during the creation of the new user – right after they are added to the database and have an ID, but before the usermeta like first_name has been saved. You can then use wp_insert_post()
to add the new post and assign them as the “author.”
<?php
// When a user first registers, run our function
add_action('user_register', 'wpse_293428_create_user_post', 10, 1);
function wpse_293428_create_user_post($user_id) {
// Set up a simple post array
$sample_post = array(
// Set to desired post type: post, page, etc.
'post_type' => 'post',
'post_title' => 'Sample Post',
// Post content can get much more complex if you need html etc.
'post_content' => 'This is a test post',
// Choose post status you want: could be a draft, or could be published
'post_status' => 'publish',
// Use the User ID that WP just created for this user
'post_author' => $user_id,
// Only if it's a Post, set Category - requires an array
'post_category' => array(1)
);
wp_insert_post($sample_post);
}
?>
You may want to change what category(ies) the new post appears in, or if you switch to creating a Page make sure to remove post_category
. Depending on your needs, filling in more complex post_content
may get a bit tricky so start simple and then slowly build out what you want.