What is the partial match string?
-
The following code if added to your themes functions.php will prevent people from registering to your wordpress site if it contains certain words, in this case “admin”. However it only works for exact match. I want to make it so that it works for partial match. What do I need to edit to achieve this?
function sozot_validate_username($valid, $username) { $forbidden = array('admin'); $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 && in_array( $username, $forbidden )) $valid=false; if ($valid && strlen($username) < 5) $valid=false; return $valid; } add_filter('validate_username', 'sozot_validate_username', 10, 2); function sozot_registration_errors($errors) { if ( isset( $errors->errors['invalid_username'] ) ) $errors->errors['invalid_username'][0] = __( 'ERROR: Invalid username.', 'sozot' ); return $errors; } add_filter('registration_errors', 'sozot_registration_errors');
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘What is the partial match string?’ is closed to new replies.