5th Year Anniversary Super Sale! Save Upto 50% OFF*

Woocommerce Registration Username Restrictions

By
1 Reviews ( 5 )

Here I explained about Woocommerce Registration form Username Restrictions. it will fix 404 error message in dashboard and buddpress pages.

update following code in functions.php to restrict symbols and special characters in username (woocommerce registration).

//WordPress Username Restrictions
function mshop_validate_username($valid, $username) {
$forbidden = array('directory', 'domain', 'download', 'downloads', 'edit', 'editor', 'email', 'ecommerce', 'forum', 'forums', 'favorite', 'feedback', 'follow', 'files', 'gadget', 'gadgets', 'games', 'guest', 'group', 'groups', 'homepage', 'hosting', 'hostname', 'httpd', 'https', 'information', 'image', 'images', 'index', 'invite', 'intranet', 'indice', 'iphone', 'javascript', 'knowledgebase', 'lists','websites', 'webmaster', 'workshop', 'yourname', 'yourusername', 'yoursite', 'yourdomain');
$pages = get_pages();
foreach ($pages as $page) {
$forbidden[] = $page->post_name;
}
if(!$valid || is_user_logged_in() && current_user_can('create_users') ) return $valid;
$username = strtolower($username);
if ($valid && strpos( $username, ' ' ) !== false) $valid=false;
if ($valid && strpos( $username, '.' ) !== false) $valid=false;
if ($valid && in_array( $username, $forbidden )) $valid=false;
if ($valid && strlen($username) < 5) $valid=false; return $valid; } add_filter('validate_username', 'mshop_validate_username', 10, 2); function mshop_registration_errors($errors) { if ( isset( $errors->errors['invalid_username'] ) )
$errors->errors['invalid_username'][0] = __( 'ERROR: Invalid username.', 'sozot' );
return $errors;
}
add_filter('registration_errors', 'mshop_registration_errors');

Show Buttons
Hide Buttons