Limit username to specific characters (A-Z and 0-9)

Using the regex posted by Moaz (and adding capitals), we will need to hook into the registration_errors filter: // Restrict username registration to alphanumerics add_filter(‘registration_errors’, ‘limit_username_alphanumerics’, 10, 3); function limit_username_alphanumerics ($errors, $name) { if ( ! preg_match(‘/^[A-Za-z0-9]{3,16}$/’, $name) ){ $errors->add( ‘user_name’, __(‘<strong>ERROR</strong>: Username can only contain alphanumerics (A-Z 0-9)’,’CCooper’) ); } return $errors; }

Alphanumeric usernames and error message for it

Check for alphanumeric For more details, look at the regex Q on SO. $name=”input string 123″; // Doesn”t allow: // Pre-/Appending white space // Not more than one space in between // Non-alphanumeric characters (lower case) if( ! preg_match( “/^[a-z0-9]+([\\s]{1}[a-z0-9]|[a-z0-9])+$/i”, $name ) ) { // Output Error Message } // Or: Does only allow // … Read more

Fetch data from a WP page with same name as current username

According with docs, when you want to retrieve field attached to post using get_field / the_field you should pass a numeric ID as 2nd argument. You are passing a string. So your code should work if: $login = wp_get_current_user()->user_login; $page = $login ? get_page_by_path( $login ) : false; $field = $page ? get_field(‘my_custom_field’, $page->ID) : … Read more

Username from e-mail

As far as i know there is no hook or filter to provide a custom User name for default registration process, however if you really want to modify it, you can alter the $_POST data. here is the sample code: add_action(‘wp_loaded’, ‘wpse_138736_filter_username’); function wpse_138736_filter_username(){ //your code to extract username from email $_POST[‘user_login’] = ‘test’; } … Read more