1

The WordPress registration default function just have 3 options:

 <?php wp_create_user( $username, $password, $email ); ?>

If I want to add some other fileds, like age or somtehing else! with written PHP form, how can I do this?

wp_users have some columns, like user_login & user_email $ user_status. Can I add new column like age? And, if I can, how can I register it with php page?

Like function:

wp_create_user( $username, $password, $email ,$age);

If it's impossible, how can I create a new table, like wp_specialusers and access to it using PHP, like:

wpdb::query('insert something to wp_specialusers..?') or
mysql_query('insert ...')

I want like this

<?php /* Template Name: wallet */ ?>
<?php get_header(); ?>
<form action=" --->WHERE!?<--- " method="post">
AGE : <input type="text" name="age">
<button type="submit">
</form>

tnx a lot

Danial Qsk
  • 87
  • 1
  • 9
  • 1
    No, you don’t do this by adding new columns to the user table, nor by creating your own table. Use the proper meta data functionality as it already exists! https://codex.wordpress.org/Function_Reference/add_user_meta – CBroe Apr 26 '18 at 13:40
  • tanx but its just can change user meta if i want set user name or lastname Simultaneous sign up i cant use it – Danial Qsk Apr 26 '18 at 14:01
  • Maybe you should rather look into ACF then. That provides relatively easy ways to configure additional meta fields, _and_ to automatically attach according form fields in different places (such as the user profile.) – CBroe Apr 26 '18 at 14:15

1 Answers1

0

You first need to use the wp_create_user( $username, $password, $email ) function like you originally have and then you need to run the wp_update_user() function afterwards to insert additional data. The additional data columns should already exist. If you want to add custom additional user data then you should use a plugin such as AdvancedCustomFields

<?php
$user_id = // ID of the user you just created;

$website = 'http://example.com'; // additional data

$user_data = wp_update_user( 
   array( 
     'ID' => $user_id,
     'user_url' => $website
   )
);

if ( is_wp_error( $user_data ) ) {
    // There was an error; possibly this user doesn't exist.
    echo 'Error.';
} else {
    // Success!
    echo 'User profile updated.';
}
?>

Update: OP wants to insert additional data at the same time of creation.

Then use wp_insert_user()

// Extra info to add
$website = "http://example.com";
$nickname = "Superman";
$description = "My description."

$userdata = array(
    'user_login' =>  'login_name',
    'user_url'   =>  $website,
    'nickname'   =>  $nickname,
    'description'=>  $description,
    'user_pass'  =>  NULL // When creating an user, `user_pass` is expected.
);

$user_id = wp_insert_user( $userdata ) ;

// On success.
if ( ! is_wp_error( $user_id ) ) {
    echo "User created : ". $user_id;
}
ProEvilz
  • 5,310
  • 9
  • 44
  • 74
  • i want user do it At the same time with sign up i think it has 2 levels – Danial Qsk Apr 26 '18 at 14:02
  • @DanialQsk you want users to add `php` code? you should write your own logic, which users will use.ex. - if you added code for processing/adding field {`Like football` : yes/no }, then you should to add input with php/html related to `Like Football`, and after add php code to process it ( clear and check input ), and after add information into `usermeta` table. what's not clear from written above? – Samvel Aleqsanyan Apr 26 '18 at 14:07
  • nooo i just want my simple sign up form white some more options like age telephon and other else – Danial Qsk Apr 26 '18 at 14:10
  • so, use `add_user_meta()` function. it'll add any fields you want into `usermeta` table of your database. and will relate to the user – Samvel Aleqsanyan Apr 26 '18 at 14:13
  • i want it at the same time with – Danial Qsk Apr 26 '18 at 14:31
  • 1
    @DanialQsk `wp_create_user()` returns the `ID` of the last person if it is successful in creating the user. I've updated my answer with a different function. You should really watch some basic tutorials on how WP works, or better yet, just read the documentation. – ProEvilz Apr 26 '18 at 16:00