Join the Voxel Guide Community!

Get Involved

Auto Create Collection on Account Creation

Description/Instructions

This snippet will create a collection for the user when they make an account. It will be named “USERNAME’s COLLECTION”

If this snippet helped, feel free to buy me a taco :)

function create_post_for_new_user($user_id){
$user = get_userdata($user_id);
$username = $user->user_login;
 
// Post data
$post_data = array(
'post_author' => $user_id,
'post_title' => $username . "'s collection",
'post_status' => 'publish',
'post_type' => 'collection'
);
 
// Create the new post
wp_insert_post($post_data);
}
 
// Hook into 'user_register'
add_action('user_register', 'create_post_for_new_user');

  • PHP
Copy Code

Let's Chat About this Snippet

Chat Toggle
Voxel Guide AI
Voxel Guide AI
Voxel Guide AI
Voxel Guide AI
Ask me anything about Voxel!
Send
Powered by AI24