看见register_form 用于修改注册表的操作挂钩
add_action( "register_form", function() {
$html = \'<p>\'.__(\'Do you want to buy or sell?<br>Choose your role\').\'</p>\';
$html .= \'<p>\';
$html .= \'<label for="_customer"><input type="radio" name="user_role" id="_customer" value="customer"/>\'.__(\'Customer\').\'</label><br>\';
$html .= \'<label for="_vendor"><input type="radio" name="user_role" id="_vendor" value="_vendor"/>\'.__(\'Customer\').\'</label>\';
$html .= \'</p>\';
echo $html;
} );
您可以使用
user_register 保存所选用户角色的操作。
add_action( "user_register", function( $user_id ) {
$allowed = array( \'customer\', \'vendor\' );
if( isset( $_POST[\'YourFieldName\'] ) && in_array( $_POST[\'YourFieldName\'], $allowed ) ){
$user = new WP_User( $user_id );
$user->set_role($_POST[\'YourFieldName\']);
}
} );
检查
WP_User 类引用
document 了解更多信息;