自动为每个用户创建帖子并为其分配模板

I'm trying to get wordpress to create new page or post for every user and asign a given template to it. It creates the post/page as expected but doesn't attatch any template to it. Any ideas on how this can help. My code is as shown b elow.

function my_create_page($user_id){
    $the_user = get_userdata($user_id);
    $new_user_name = $the_user->user_login;
    $my_post = array();
    $my_post['post_title'] = $new_user_name;
    $my_post['post_type'] = 'page';
    $my_post['post_content'] = '';
    $my_post['post_status'] = 'publish';
    $my_post['post_theme'] = 'user-profile';
    wp_insert_post( $my_post );
}
add_action('user_register', 'my_create_page', 'user-profile.php');

You're just missing one line:

function my_create_page($user_id){
    $the_user = get_userdata($user_id);
    $new_user_name = $the_user->user_login;
    $my_post = array();
    $my_post['post_title'] = $new_user_name;
    $my_post['post_type'] = 'page';
    $my_post['post_content'] = '';
    $my_post['post_status'] = 'publish';
    $my_post['post_theme'] = 'user-profile';

    $my_post['page_template'] = 'name-of-template.php';

 wp_insert_post( $my_post );
}
add_action('user_register', 'my_create_page', 'user-profile.php'); 

Codex: wp_insert_post