$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>php - How do I create a new post upon registration with the users first and last name as title|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

php - How do I create a new post upon registration with the users first and last name as title

matteradmin9PV0评论

I've been working at this for some time and for the life of me I cannot figure this out. Here is my code as of now.

add_action('user_register','create_new_user_profile', 999);

function create_new_user_profile($user_id){
    if (!$user_id>0)
            return;

    $user_info = get_userdata($user_id);
    $profile_full_name = $user_info->first_name .  " " . $user_info->last_name;

    $profile_post = array(
         'post_title' => $profile_full_name,
         'post_content' => 'This is the profile post.',
         'post_status' => 'publish',
         'post_type'    => 'Team',
         'post_author' => $user_id
    );

    $profile = wp_insert_post( $profile_post );

}

I've tried several things and searched for some time, the current code returns an empty string, but through other alternatives I've been able to post the username or user_id as the title, but I cant get the display_name or a combination of the first and last name which is what I'm in need of.

I've been working at this for some time and for the life of me I cannot figure this out. Here is my code as of now.

add_action('user_register','create_new_user_profile', 999);

function create_new_user_profile($user_id){
    if (!$user_id>0)
            return;

    $user_info = get_userdata($user_id);
    $profile_full_name = $user_info->first_name .  " " . $user_info->last_name;

    $profile_post = array(
         'post_title' => $profile_full_name,
         'post_content' => 'This is the profile post.',
         'post_status' => 'publish',
         'post_type'    => 'Team',
         'post_author' => $user_id
    );

    $profile = wp_insert_post( $profile_post );

}

I've tried several things and searched for some time, the current code returns an empty string, but through other alternatives I've been able to post the username or user_id as the title, but I cant get the display_name or a combination of the first and last name which is what I'm in need of.

Share Improve this question edited Feb 27, 2019 at 2:00 Dobbs asked Feb 27, 2019 at 1:37 DobbsDobbs 32 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

The get_userdata function is what you are looking for. So for the display_name it would be

$user_info = get_userdata($user_id);
$profile_display_name = $user_info->display_name;

And for first and last name it would be

$full_name = $user_info->first_name .  " " . $user_info->last_name;
Post a comment

comment list (0)

  1. No comments so far