在函数中按照这条线放一些东西。php或插件。它可能需要一些调整和修改,它不是一个“原样”的例子,但它应该让你走上正确的道路。
下面将向默认注册表中添加一个新的字段UI,然后检查其长度是否为11个字符,以及其他用户是否具有相同的UID。它将UID存储在用户元数据中。
如果您有自定义注册表,输入名为“user\\u uid”的文本就足够了,要获取用户的uid,请使用:$uid = get_the_author_meta( \'user_uid\', $user->ID );
示例如下:
<?php
add_action(\'register_form\',\'show_uid_field\');
add_action(\'register_post\',\'check_fields\',10,3);
add_action(\'user_register\', \'register_extra_fields\');
function show_uid_field(){
?>
<p>
<label>Unique ID<br />
<input id="user_uid" class="input" type="text" tabindex="20" size="25" value="<?php echo $_POST[\'user_uid\']; ?>" name="first"/>
</label>
</p>
<?php
}
function check_fields($login, $email, $errors) {
global $user_uid;
if ($_POST[\'user_uid\'] == \'\') {
$errors->add(\'empty_user_uid\', "<strong>ERROR</strong>: Please Enter your UID");
} else {
$user_uid = $_POST[\'user_uid\'];
if(strlen(trim($user_uid)) != 11){
$errors->add(\'invalid_user_uid\', "<strong>ERROR</strong>: Invalid value, please Enter your UID");
} else {
$szSort = "user_nicename";
$aUsersID = $wpdb->get_col( $wpdb->prepare( "SELECT $wpdb->users.ID FROM $wpdb->users ORDER BY %s ASC", $szSort ));
foreach ( $aUsersID as $iUserID ) {
$user = get_userdata( $iUserID );
$uid = get_the_author_meta( \'user_uid\', $user->ID );
if($uid == $user_uid){
$errors->add(\'notunique_user_uid\', "<strong>ERROR</strong>: This UID is already taken, please enter your UID");
break;
}
}
// do your soap check here
}
}
}
function register_extra_fields($user_id, $password="", $meta=array()) {
update_usermeta( $user_id, \'user_uid\', $_POST[\'user_uid\'] );
}
?>
我还想指出,虽然重力的形成是伟大的,但如果你试图将其延伸到一个痛苦的世界。