wordprss结账界面页面调整
1.去除重置密码邮箱找回,隐藏登录表单中的“忘记密码?”链接(登录界面以及登录失败界面)
使用CSS隐藏,在WordPress后台,转到外观 > 自定义 > 额外CSS,然后添加以下代码
.woocommerce-form-login .lost_password {
display: none;
}
a[href*="lost-password"] {
display: none;
}
2.用户名或邮箱登录 改成用户名登录(functions.php)
function force_username_login( $user, $username, $password ) {
// Check if the login attempt is using an email
if ( strpos( $username, '@' ) !== false ) {
// If it's an email, reject the login attempt
return new WP_Error( 'invalid_email', __( 'Invalid username.' ) );
}
return $user;
}
add_filter( 'authenticate', 'force_username_login', 10, 3 );
3.用户结算页登录栏添加提示语(functions.php)
//忘记密码 改为 If you forget your password, please contact our customer service for assistance !
add_action('wp_footer', function() {
?>
<script>
(function() {
var newText = document.createElement('p');
newText.textContent = 'If you forget your password, please contact our customer service for assistance !';
var loginForm = document.querySelector('.woocommerce-form-login');
if (loginForm) {
loginForm.appendChild(newText);
}
})();
</script>
<?php
});
4.60分钟内限制错误次数不能超3次(functions.php)
// 60分钟内错误次数超3次
function limit_login_attempts($username) {
$ip = $_SERVER['REMOTE_ADDR'];
$transient_name = 'login_attempts_'. $ip;
$attempts = get_transient($transient_name);
if (false === $attempts) {
$attempts = 1;
} else {
$attempts++;
}
set_transient($transient_name, $attempts, 60 * 60);
if ($attempts >= 3) {
wp_die('Too many login attempts have been made incorrectly. Please try again in one hour!');
}
}

浙公网安备 33010602011771号