我已成功地将此代码集成到函数中。php
//1. Add a new form element...
add_action( \'register_form\', \'myplugin_register_form\' );
function myplugin_register_form() {
global $wp_roles;
echo \'<label for="role">Type de client</label>\';
echo \'<select name="role" class="input">\';
foreach ( $wp_roles->roles as $key=>$value ) {
// Exclude default roles such as administrator etc. Add your own
if ( in_array( $value[\'name\'], [ \'Client\', \'Entreprise\'] )) {
echo \'<option value="\'.$key.\'">\'.$value[\'name\'].\'</option>\';
}
}
echo \'</select>\';
}
//2. Add validation.
add_filter( \'registration_errors\', \'myplugin_registration_errors\', 10, 3 );
function myplugin_registration_errors( $errors, $sanitized_user_login, $user_email ) {
if ( empty( $_POST[\'role\'] ) || ! empty( $_POST[\'role\'] ) && trim( $_POST[\'role\'] ) == \'\' ) {
$errors->add( \'role_error\', __( \'<strong>ERROR</strong>: You must include a role.\', \'mydomain\' ) );
}
return $errors;
}
//3. Finally, save our extra registration user meta.
add_action( \'user_register\', \'myplugin_user_register\' );
function myplugin_user_register( $user_id ) {
$user_id = wp_update_user( array( \'ID\' => $user_id, \'role\' => $_POST[\'role\'] ) );
}
它在默认WP注册页面上按预期工作。
我用于projet的主题有一个自定义的模式登录/注册窗口,我希望此代码也能在此窗口中工作。
请参见默认注册窗口:https://capricesdelectables.com/wp-login.php?action=register
请参见自定义登录框:https://capricesdelectables.com (单击“Connexion”右上角的红色链接)
此模式窗口以特定mytheme登录名为模板。php文件
如何从函数调用代码。php使其显示在此模式窗口中?
谢谢