phpBB usernames migrated/added into WordPress with native language characters

User avatar
axew3
w3all User
w3all User
Posts: 2866
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Contact:

phpBB usernames migrated/added into WordPress with native language characters

Post by axew3 »

Note: plugin version 2.9.0 >

Any NON Latin phpBB username (any language), will be added as transliterated in Latin into WordPress, by default.
If the 'transliterator_transliterate' function is not available, because it is not configured in PHP (but it commonly is) then the NON Latin username will probably not be correctly processed by WordPress and the user transfer will fail (user not transferred/created in WP). In this case, an array of languages/chars could be provided to workaround the lacking of the 'transliterator_transliterate' Php native function, but by default the code will not provide it. Anyway as said, the 'transliterator_transliterate' function is commonly available into any Php.

To add phpBB users in WordPress using native characters of phpBB usernames:


add this into the wp-config.php file

Code: Select all

define( 'WPW3ALL_USE_UNAME_NATIVE_LANG_CHARS', 1 );
after the line

Code: Select all

/* Add any custom values between this line and the "stop editing" line. */
now for example the Cyrillic username двойняшки will be transferred/created into WP as двойняшки (Cyrillic)

Once it has been added into the wp-config.php file, the username will be transferred/added into WordPress with his (same) username like it is into phpBB, but purged as explained more below.

*NOTE: worth also to mention that, into my tests, and even using a default WordPress setting it let say as Cyrillic as example, after that an user has been added with Cyrillic chars, when the user go to update his profile, WordPress answer with an error about failed user addition (that happen into a default wordpress and not due to the plugin integration code that during tests have been also disabled), and there is no way to update the user's profile into WP, answer by WordPress is:
Cannot create a user with an empty login name.
My question (that i have not investigate) is:
what it do a WordPress configured in a non Latin language when usernames are not into Latin and how it is managed?
The code should work fine into any "modified" (??) WordPress that allow to manage native non Latin usernames into WordPress (if it is the way that it is done, or some other).

Any characters/languages for usernames: how it work

Code: Select all

define( 'WPW3ALL_USE_UNAME_NATIVE_LANG_CHARS', 1 );
Considered alphabets are

Code: Select all

Arabic,Armenian,Bengali,Bopomofo,Braille,Buhid,Canadian_Aboriginal,Cherokee,Cyrillic,Devanagari,Ethiopic,Georgian,Greek,Gujarati,Gurmukhi,Han,Hangul,Hanunoo,Hebrew,Hiragana,Inherited,Kannada,Katakana,Khmer,Lao,Latin,Limbu,Malayalam,Mongolian,Myanmar,Ogham,Oriya,Runic,Sinhala,Syriac,Tagalog,Tagbanwa,TaiLe,Tamil,Telugu,Thaana,Thai,Tibetan,Yi
The integration code by default, if no option via DEFINE into the wp-config.php as been set, will add phpBB usernames that are not Latin into WordPress, transliterated to Latin.

If

Code: Select all

define('WPW3ALL_USE_DEFAULT_WP_UCHARS', 1);
option is set, usernames into WordPress will be added as sanitized allowing these chars also into a WP MUMS multisite:

Code: Select all

-0-9A-Za-z _.@
if not and if WP is MUMS, the username will added after that it has been purged from unwanted characters, so allowing only letters and numbers:

Code: Select all

0-9A-Za-z 
if

Code: Select all

define( 'WPW3ALL_USE_UNAME_NATIVE_LANG_CHARS', 1 );
is set, usernames are added into WordPress using the native language, after that it has been sanitized by unwanted characters (exactly like the Latin) like above mentioned.
The correct cleanup of the username by unwanted characters in any native language is performed using regular expressions.

The new added and used function that allow this, will reside into:
/wp-content/plugins/wp-w3all-phpbb-integration/common/helpers.php

It will start looking definitively like this:

Code: Select all

# function w3all_detectClean_language_chars

# Detect any text language
##$test = w3all_detectClean_language_chars($text, false, false, true);
// and return one of these
// Arabic,Armenian,Bengali,Bopomofo,Braille,Buhid,Canadian_Aboriginal,Cherokee,Cyrillic,Devanagari,Ethiopic,Georgian,Greek,Gujarati,Gurmukhi,Han,Hangul,Hanunoo,Hebrew,Hiragana,Inherited,Kannada,Katakana,Khmer,Lao,Latin,Limbu,Malayalam,Mongolian,Myanmar,Ogham,Oriya,Runic,Sinhala,Syriac,Tagalog,Tagbanwa,TaiLe,Tamil,Telugu,Thaana,Thai,Tibetan,Yi

# return sanitized text for -> MUMS that allow only '[0-9A-Za-z]'
##$test = w3all_detectClean_language_chars($text, true);

# return sanitized text for -> default WP '[-0-9A-Za-z _.@]'
##$test = w3all_detectClean_language_chars($text, false, false, false);

# return text transliterated to Latin text
##$test = w3all_detectClean_language_chars($text, false, true);

function w3all_detectClean_language_chars($text, $return_x_mums = false, $returnLatin = false, $returnDetectLang = false)
{
...
...