要执行此操作,首先您必须退出队列\'wc-password-strength-meter\'
编写脚本,然后使用\'validate_password_reset\'
钩子以应用自定义验证。
以下代码可用于验证最少8个字符,最多20个字符,并且必须至少包含一个大写字母、数字和特殊字符。
使用退出队列脚本\'wp_print_scripts\'
钩
使用自定义验证\'validate_password_reset\'
钩
function geek_wc_remove_password_strength(){
if ( wp_script_is( \'wc-password-strength-meter\', \'enqueued\' ) ) {
wp_dequeue_script( \'wc-password-strength-meter\' );
}
}
add_action( \'wp_print_scripts\', \'geek_wc_remove_password_strength\', 100 );
add_action(\'validate_password_reset\',\'geek_validate_password_reset\',10,2);
function geek_validate_password_reset($errors, $user){
$exp = \'/^(?=.*[A-Za-z])(?=.*[A-Z])(?=.*[@$!%*#?&])[A-Za-z\\d@$!%*#?&]{8,20}$/\';
if(strlen($_POST[\'password_1\'])<8 || !preg_match($exp, $_POST[\'password_1\']) ){
$errors->add( \'error\', \'Hint: Password length must be minimum 8 characters and maximum 20, and must contain at least one capital letter, number and punctuation mark.\',\'\');
}
}