Created
February 25, 2016 16:53
-
-
Save mathieuhays/6298e2bdc8d127ec3c3a to your computer and use it in GitHub Desktop.
Fix PMPRO username issue
This file contains hidden or 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 | |
| function pmpro_fix_username_issue( $pmpro_continue_registration ) { | |
| if (!$pmpro_continue_registration) { | |
| return $pmpro_continue_registration; | |
| } | |
| global $username, $pmpro_error_fields; | |
| $safe_username = sanitize_user($username, true); | |
| $shouldReturn = false; | |
| // Check for invalid characters | |
| if ($username !== $safe_username) { | |
| pmpro_setMessage("The username specified contains forbidden characters.", "pmpro_error"); | |
| $pmpro_error_fields[] = "username"; | |
| $shouldReturn = true; | |
| } | |
| // Check if username exists | |
| if (username_exists($safe_username) || username_exists($username)) { | |
| pmpro_setMessage("The username specified already exists.", "pmpro_error"); | |
| $pmpro_error_fields[] = "username"; | |
| $shouldReturn = true; | |
| } | |
| if ($shouldReturn) return false; | |
| return $pmpro_continue_registration; | |
| } | |
| add_filter( 'pmpro_registration_checks', 'pmpro_fix_username_issue'); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: the second check is probably useless as I think PMPRO already checks if the username exists. Should drop it