Created
December 25, 2012 11:41
-
-
Save remkus/4372815 to your computer and use it in GitHub Desktop.
Prevent spaces in BuddyPress usernames
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'bp_loaded','bpdev_remove_bp_pre_user_login_action') ; | |
/** | |
* BuddyPress replaces the space with '-' which is not known to the user | |
* We remove the attached function to stop BP from circumventing the space in username | |
* | |
*/ | |
function bpdev_remove_bp_pre_user_login_action(){ | |
remove_action( 'pre_user_login', 'bp_core_strip_username_spaces' ); | |
} | |
add_filter( 'validate_username','bpdev_restrict_space_in_username',10,2) ; | |
/** | |
* add a filter to invalidate a username with spaces | |
* | |
*/ | |
function bpdev_restrict_space_in_username( $valid,$user_name ){ | |
//check if there is an space | |
if ( preg_match('/\s/',$user_name ) ) | |
//if yes, then we say it is an error | |
return false; | |
//otherwise return the actual validity | |
return $valid; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment