我是WordPress和PHP的新手。我正在尝试更新一个字段,以便在客户注册后立即在客户记录中输入唯一的编号。我写了一些我认为应该有用的东西,但看在上帝的份上,它什么也做不了。帮助
add_action (\'user_register\', \'mailboxNumberGenerator\', 10, 1);
function mailboxNumberGenerator($current_user)
{
$initialMailboxNum = 100000;
$user_query = new WP_User_Query( array( \'role\' => \'Customer\' ) );
$user_query2 = new WP_User_Query( array( \'role\' => \'Subscriber\' ) );
$currentMailboxNum = $initialMailboxNum
+ $user_query->get_total() + $user_query2->get_total();
$newMailboxNum = $currentMailboxNum + 1;
global $current_user;
get_currentuserinfo();
update_user_meta ($user_id, \'nickname\', $newMailboxNum);
}
SO网友:Aniruddha Gawade
你的钩子已经给了你用户id,你不需要$current_user
.
add_action (\'user_register\', \'mailboxNumberGenerator\', 10, 1);
function mailboxNumberGenerator($user_id)
{
$initialMailboxNum = 100000;
$user_query = new WP_User_Query( array( \'role\' => \'Customer\' ) );
$user_query2 = new WP_User_Query( array( \'role\' => \'Subscriber\' ) );
$currentMailboxNum = $initialMailboxNum
+ $user_query->get_total() + $user_query2->get_total();
$newMailboxNum = $currentMailboxNum + 1;
update_user_meta ($user_id, \'nickname\', $newMailboxNum);
}