我正在尋找一種更好的方式來隱藏wordpress註冊表單上的用戶名。目前,我已經開始工作了,但它不方便用戶使用,因爲表單會重新要求註冊人「請輸入您的電子郵件地址」(即使他們已經這樣做了)。這可以在safetyworks.com/login上看到。隱藏用戶名wordpress註冊
這裏是我的代碼的上半部分:
<?php
$current_email = isset($_POST['user_email']) ? $_POST['user_email'] : '';
$current_username = $current_email;
?>
<?php if ($this->should_print_form()) : ?>
<?php $this->print_form_header(); ?>
<div class="row clearfix">
<div class="col-sm-10 col-md-8 col-sm-offset-1 col-md-offset-2">
<div class="panel panel-primary panel-border top">
<div class="panel-heading">
<span class="panel-title fs-lg"><i class="fa fa-edit"></i> <?php _e('Create an account', 'cuarlf'); ?></span>
</div>
<div class="panel-body">
<div class="form-group mb-lg">
<label for="user_email" class="control-label top-label"><?php _e('Email Address', 'cuarlf'); ?></label>
<div class="row clearfix">
<div class="col-xs-12">
<span class="append-icon right"><i class="field-icon fa fa-asterisk text-muted"></i></span>
<input class="form-control" type="email" name="user_email" id="user_email" value="<?php echo esc_attr($current_email); ?>">
<input class="form-control" type="hidden" name="user_login" id="user_login" value="<?php echo $current_username; ?>">
</div>
</div>
</div>
那麼,有沒有更好的方法來隱藏用戶名?我嘗試使用智能WP登錄,但該WordPress仍然希望指定用戶名。我也嘗試了類似Smart WP登錄諾言但失敗的功能。
我發現WP-Customer Area插件有一個導致這個問題的函數。
public static function register_new_user($user_login, $user_email)
{
global $wpdb;
$errors = new WP_Error();
$sanitized_user_login = sanitize_user($user_login);
$user_email = apply_filters('user_registration_email', $user_email);
// Check the username
if ($sanitized_user_login == '')
{
$errors->add('empty_username', __('Please enter a username.', 'cuarlf'));
}
elseif (!validate_username($user_login))
{
$errors->add('invalid_username', __('Sorry. Please enter a username using only lowercase letters and numbers.', 'cuarlf'));
$sanitized_user_login = '';
}
elseif (username_exists($sanitized_user_login))
{
$errors->add('username_exists', __('This username is already registered. Please choose another one.', 'cuarlf'));
}
// Check the email address
if ($user_email == '')
{
$errors->add('empty_email', __('Please type your email address.', 'cuarlf'));
}
elseif (!is_email($user_email))
{
$errors->add('invalid_email', __('The email address isn’t correct.', 'cuarlf'));
$user_email = '';
}
elseif (email_exists($user_email))
{
$errors->add('email_exists', __('This email is already registered, please choose another one.', 'cuarlf'));
}
do_action('register_post', $sanitized_user_login, $user_email, $errors);
$errors = apply_filters('registration_errors', $errors, $sanitized_user_login, $user_email);
if ($errors->get_error_code())
{
return $errors;
}
$user_pass = wp_generate_password(12, false);
$user_id = wp_create_user($sanitized_user_login, $user_pass, $user_email);
if (!$user_id)
{
$errors->add('registerfail',
sprintf(__('Couldn’t register you... please contact the <a href="mailto:%s">webmaster</a> !', 'cuarlf'), get_option('admin_email')));
return $errors;
}
update_user_option($user_id, 'default_password_nag', true, true); //Set up the Password change nag.
// Generate something random for a key...
$activation_key = wp_generate_password(20, false);
do_action('retrieve_password_key', $user_login, $activation_key);
// Now insert the new md5 key into the db
$wpdb->update($wpdb->users, array('user_activation_key' => $activation_key), array('user_login' => $user_login));
// Send notifications
$user = get_userdata($user_id);
self::new_user_notification_admin($user);
self::new_user_notification($user, $activation_key);
return $user_id;
}
問題是爲什麼表單認爲電子郵件地址爲空?
這是我沒有成功嘗試的功能 - https://wordpress.stackexchange.com/questions/52302/is-it-possible-to-remove-username-field-from-the-registration-頁面,如果那麼如何 – timrosenthal