$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'); ?>custom field - adding extra wordpress user info from registration form|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)

custom field - adding extra wordpress user info from registration form

matteradmin10PV0评论

I am trying to add some extra user profile information from a wordpress registration form. But only the standard wordpress user info is being added. Can this work just using wp_insert_user or do I need to add an extra function for wp_update_user ?

thank you. ( I am very much a beginner at coding, so sorry if this is obvious)

    function crm_wp_insert_user() {
      if ( isset($_POST['crm_customer_submitted'] ) ) {

      $firstname   =   sanitize_user( $_POST['firstname'] );
      $lastname   =   sanitize_user( $_POST['lastname'] );
      $project   =   sanitize_user( $_POST['project'] );
      $email      =   sanitize_email( $_POST['email'] );
      $phone      =   sanitize_user( $_POST['phone'] );   
      $address      =   sanitize_user( $_POST['address'] );       


    $user_data = array(
        //'ID' => '',
        'user_pass' => wp_generate_password(),
        'user_login' => $email,
        'user_nicename' => $firstname,
        'user_url' => '',
        'user_email' => $email,
        'display_name' => $firstname,
        'nickname' => $firstname,
        'first_name' => $firstname,
        'last_name' => $lastname,
        'description' => $project,
        'phone' => $phone,  
        'address' => $address,      
        'user_registered' => $date,
        'role' => crm_client // Use default role or another role, e.g. 'editor'
    );
    $user_id = wp_insert_user( $user_data );
      }

}
add_action( 'admin_init', 'crm_wp_insert_user' );

I am trying to add some extra user profile information from a wordpress registration form. But only the standard wordpress user info is being added. Can this work just using wp_insert_user or do I need to add an extra function for wp_update_user ?

thank you. ( I am very much a beginner at coding, so sorry if this is obvious)

    function crm_wp_insert_user() {
      if ( isset($_POST['crm_customer_submitted'] ) ) {

      $firstname   =   sanitize_user( $_POST['firstname'] );
      $lastname   =   sanitize_user( $_POST['lastname'] );
      $project   =   sanitize_user( $_POST['project'] );
      $email      =   sanitize_email( $_POST['email'] );
      $phone      =   sanitize_user( $_POST['phone'] );   
      $address      =   sanitize_user( $_POST['address'] );       


    $user_data = array(
        //'ID' => '',
        'user_pass' => wp_generate_password(),
        'user_login' => $email,
        'user_nicename' => $firstname,
        'user_url' => '',
        'user_email' => $email,
        'display_name' => $firstname,
        'nickname' => $firstname,
        'first_name' => $firstname,
        'last_name' => $lastname,
        'description' => $project,
        'phone' => $phone,  
        'address' => $address,      
        'user_registered' => $date,
        'role' => crm_client // Use default role or another role, e.g. 'editor'
    );
    $user_id = wp_insert_user( $user_data );
      }

}
add_action( 'admin_init', 'crm_wp_insert_user' );
Share Improve this question edited Jan 24, 2019 at 6:16 Pratik Patel 1,1091 gold badge11 silver badges23 bronze badges asked Jan 24, 2019 at 5:24 SpeedySpeedy 132 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

You can use usermeta wordpress function to add extra information for user, below code will help you


function crm_wp_insert_user() {
  if ( isset($_POST['crm_customer_submitted'] ) ) {

  $firstname   =   sanitize_user( $_POST['firstname'] );
  $lastname   =   sanitize_user( $_POST['lastname'] );
  $project   =   sanitize_user( $_POST['project'] );
  $email      =   sanitize_email( $_POST['email'] );
  $phone      =   sanitize_user( $_POST['phone'] );   
  $address      =   sanitize_user( $_POST['address'] );       


$user_data = array(
    //'ID' => '',
    'user_pass' => wp_generate_password(),
    'user_login' => $email,
    'user_nicename' => $firstname,
    'user_url' => '',
    'user_email' => $email,
    'display_name' => $firstname,
    'nickname' => $firstname,
    'first_name' => $firstname,
    'last_name' => $lastname,    
    'user_registered' => $date,
    'role' => crm_client // Use default role or another role, e.g. 'editor'
);
$user_id = wp_insert_user( $user_data );

//Below function will add extra details to user
add_user_meta($user_id,'description',$project);
add_user_meta($user_id,'phone',$phone);
add_user_meta($user_id,'address',$address);

  }
} add_action( 'admin_init', 'crm_wp_insert_user' );

Post a comment

comment list (0)

  1. No comments so far