带有 php 的 wordpress 用户注册可选字段

wordpress user registration optional fileds with php

WordPress注册默认功能只有3个选项:

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

如果我想添加一些其他文件,例如 agesomtehing else! 使用书面 PHP 表格,我该怎么做?

wp_users 有一些列,比如 user_login & user_email $ user_status。我可以添加像 age 这样的新列吗? 而且,如果可以的话,我怎样才能在 php 页面注册它?

喜欢的功能:

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

如果不可能, 我怎样才能创建一个新的 table,比如 wp_specialusers 并使用 PHP 访问它,例如:

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

我想要这样

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

tnx 很多

您首先需要像原来那样使用 wp_create_user( $username, $password, $email ) 函数,然后您需要 运行 wp_update_user() 函数以插入其他数据。附加数据列应该已经存在。如果您想添加自定义的额外用户数据,那么您应该使用诸如 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.

然后使用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;
}