【发布时间】:2021-06-20 06:34:35
【问题描述】:
我需要从 WordPress 后端添加用户。所以,我想为他们生成唯一的用户 ID。但我可以实现它。有人可以帮我解决这个问题吗?
这是到目前为止我拍摄的内容。如果我可以将 WordPress 默认生成的唯一用户 ID 附加到我的字段末尾会更好。
// Customize the user fields
function custom_user_profile_fields($user) {
$rand = randomGen(1000,5000,1);
$auth_Token = '2021-ABCD-'.$rand[0];
?>
<h3>Profile Information</h3>
<table class="form-table">
<tr>
<th><label for="srn">Student Registration Number</label></th>
<td>
<input type="text" class="regular-text" name="srn" value="<?php echo (get_option('srn') ? esc_attr( get_the_author_meta( 'srn', $user->ID ) ) : $auth_Token); ?>" id="srn" readonly /><br />
</td>
</tr>
</table>
<?php
}
add_action( 'show_user_profile', 'custom_user_profile_fields' );
add_action( 'edit_user_profile', 'custom_user_profile_fields' );
add_action( "user_new_form", "custom_user_profile_fields" );
function save_custom_user_profile_fields($user_id) {
# again do this only if you can
if(!current_user_can('manage_options'))
return false;
# save my custom field
update_usermeta($user_id, 'srn', $_POST['srn']);
}
add_action('user_register', 'save_custom_user_profile_fields');
add_action('profile_update', 'save_custom_user_profile_fields');
当用户添加时,我无法将之前保存的索引号添加到该字段。它正在生成另一个并再次显示。由于我不是这方面的专家,有人可以帮我解决这个问题吗?
提前致谢
【问题讨论】:
标签: wordpress function wordpress-theming customization user-defined-functions