Ahmad Naser Turnkey Ecosystem Ahmad Naser
September 16, 2018

Support Arabic Username in WordPress registration and login

Published in the Ahmad Naser ecosystem. Estimated reading time: 1 minute.

Support Arabic Username in WordPress registration and login

function aau_sanitize_user($username, $raw_username, $strict) {
	$username = wp_strip_all_tags( $raw_username );
	$username = remove_accents( $username );
	// Kill octets
	$username = preg_replace( '|%([a-fA-F0-9][a-fA-F0-9])|', '', $username );
	$username = preg_replace( '/&.+?;/', '', $username ); // Kill entities

	// If strict, reduce to ASCII and Arabic characters for max portability.
	if ( $strict )
		$username = preg_replace( '|[^a-z\p{Arabic}0-9 _.\-@]|iu', '', $username );

	$username = trim( $username );
	// Consolidate contiguous whitespace
	$username = preg_replace( '|\s+|', ' ', $username );

	return $username;
}
add_filter('sanitize_user', 'aau_sanitize_user', 10, 3);

you can download also this plugin

Leave a Reply

Your email address will not be published. Required fields are marked *