如何向wp用户添加更多字段并将其保存到数据库

时间:2020-06-09 作者:Maxwell David

$creating = isset( $_POST[\'createuser\'] );

$new_user_login             = $creating && isset( $_POST[\'user_login\'] ) ? wp_unslash( $_POST[\'user_login\'] ) : \'\';
$new_user_firstname         = $creating && isset( $_POST[\'first_name\'] ) ? wp_unslash( $_POST[\'first_name\'] ) : \'\';
$new_user_lastname          = $creating && isset( $_POST[\'last_name\'] ) ? wp_unslash( $_POST[\'last_name\'] ) : \'\';
$new_user_email             = $creating && isset( $_POST[\'email\'] ) ? wp_unslash( $_POST[\'email\'] ) : \'\';
$new_user_uri               = $creating && isset( $_POST[\'url\'] ) ? wp_unslash( $_POST[\'url\'] ) : \'\';
$new_user_phone             = $creating && isset( $_POST[\'phone\'] ) ? wp_unslash( $_POST[\'phone\'] ) : \'\';
$new_user_role              = $creating && isset( $_POST[\'role\'] ) ? wp_unslash( $_POST[\'role\'] ) : \'\';
$new_user_send_notification = $creating && ! isset( $_POST[\'send_user_notification\'] ) ? false : true;
$new_user_ignore_pass       = $creating && isset( $_POST[\'noconfirmation\'] ) ? wp_unslash( $_POST[\'noconfirmation\'] ) : \'\';

?>
这是我的代码,但当我添加用户并保存它时,它不会在数据库中为phone添加更多字段

1 个回复
SO网友:TomC

您想使用Wordpress功能;add_user_meta

add_user_meta( $user_id, \'_level_of_awesomeness\', $awesome_level);

https://developer.wordpress.org/reference/functions/add_user_meta/

相关推荐

Database access using docker

我使用docker指南安装了一个新的wordpress项目:mkdir my-wordpress-site cd my-wordpress-site ddev config --project-type=php ddev composer create wordpress/skeleton --no-interaction --prefer-dist ddev config --docroot=wp --project-type=wordpress ddev res