求助:WordPress中PeepSo插件注册页用户名数字格式限制失效
Hey there! I totally get where you're coming from—WordPress default registration plays by its own rules, but PeepSo runs its own independent registration system, which is why your existing restriction doesn't carry over. Let's walk through two simple, beginner-friendly solutions to fix this:
Option 1: Add Custom Code to Enforce the Restriction
PeepSo lets us hook into its form validation process with custom code. You can add this snippet to your theme's functions.php file (pro tip: use a child theme so your changes don't get erased when your theme updates) or a basic custom plugin:
// Force pure numeric usernames on PeepSo registration add_filter('peepso_form_errors_register', 'enforce_numeric_peepso_username'); function enforce_numeric_peepso_username($errors) { // Grab the submitted username from PeepSo's form $username = isset($_POST['username']) ? trim($_POST['username']) : ''; // Check if the username isn't empty and isn't only numbers if (!empty($username) && !ctype_digit($username)) { // Add an error message that will show up on the registration page $errors[] = __('Username must contain only numbers.', 'your-theme-text-domain'); } return $errors; }
Just swap 'your-theme-text-domain' with your theme's actual text domain (you can find this at the top of your theme's style.css file).
Option 2: Use PeepSo's Built-in Validation (No Code Required)
If you'd rather skip coding, check if your PeepSo version has built-in field validation:
- Head to your WordPress admin → PeepSo → Configuration → Registration
- Look for the "Username" field settings (it might be under "Custom Fields" or directly in the registration form setup)
- Find an option like "Validation Rule" or "Regular Expression"
- Set the regex to
^[0-9]+$—this tells PeepSo to only accept numbers for usernames - Save your changes and test the form
Quick Checks to Ensure It Works
- Clear your site's cache (if you use a caching plugin) to make sure new rules take effect
- Test the PeepSo registration page in an incognito window to avoid cached form data
- Try submitting a username with letters or symbols to confirm the error message appears
内容的提问来源于stack exchange,提问作者Pawan Kumar

