您可以声明$success变量并使用它显示成功消息,如下所示。
如果用户成功注册,则声明$success变量并为其分配成功消息,如下所示:
$success = \'\';
if ( \'POST\' == $_SERVER[\'REQUEST_METHOD\'] && !empty( $_POST[\'action\'] ) && $_POST[\'action\'] == \'adduser\' ) {
$user_pass = wp_generate_password();
$userdata = array(
\'user_login\' => esc_attr( $_POST[\'user_name\'] ),
\'user_pass\' => esc_attr( $_POST[\'pass1\'] ),
\'user_email\' => esc_attr( $_POST[\'email\'] ),
\'user_url\' => esc_attr( $_POST[\'website\'] ),
\'description\' => esc_attr( $_POST[\'description\'] ),
\'role\' => get_option( \'default_role\' ),
);
if ( !$userdata[\'user_login\'] )
$error = __(\'A username is required for registration.\', \'frontendprofile\');
elseif ( username_exists($userdata[\'user_login\']) )
$error = __(\'Sorry, that username already exists!\', \'frontendprofile\');
elseif ( !is_email($userdata[\'user_email\'], true) )
$error = __(\'You must enter a valid email address.\', \'frontendprofile\');
elseif ( email_exists($userdata[\'user_email\']) )
$error = __(\'Sorry, that email address is already used!\', \'frontendprofile\');
else if ( $_POST[\'pass1\'] !== $_POST[\'pass2\'] ) {
$error = __(\'Sorry, Passwords must match\', \'frontendprofile\');
}
else if ( strlen( $_POST[\'pass1\'] ) < 6 ) {
$error = __(\'Sorry, Passwords must be at least six characters long\', \'frontendprofile\');
}
else{
$new_user = wp_insert_user( $userdata );
if (!is_wp_error($return) ){
$success = __($userdata[\'user_login\'].\' User registered $userdata[\'user_login\'].\', \'frontendprofile\');
wp_new_user_notification($new_user, $user_pass);
}
}
}
您可以使用$success变量显示消息,如下所示:
if($success)
echo $success;