Skip to content

Instantly share code, notes, and snippets.

@mathieuhays
Created February 25, 2016 16:53
Show Gist options
  • Select an option

  • Save mathieuhays/6298e2bdc8d127ec3c3a to your computer and use it in GitHub Desktop.

Select an option

Save mathieuhays/6298e2bdc8d127ec3c3a to your computer and use it in GitHub Desktop.
Fix PMPRO username issue
<?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');
@mathieuhays
Copy link
Copy Markdown
Author

Note: the second check is probably useless as I think PMPRO already checks if the username exists. Should drop it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment