Allow ???/???
-
Are you planning on adding support for ???/???? That would be so appreciated!
-
I second that request. ??
I will submit a filter for usernames in Swedish characters soon.
Limitation will be that you only can have WordPress configured for Profiles Permalinks with userid ie not usernames any more.
The PHP function sprintf used by many plugins for user links will fail with Swedish characters because sprintf can not handle multibytes (UTF8).
Which user member/manager plugins are you using?
I have a solution tested with WP User Manager and Ultimate Member.
Hello!
@missveronicatv Did you have a solution for ultimate members? Could you please tell me about how you did it?
// Overrides the WordPress sanitize_user filter
// to allow Swedish/Danish and English characters only
// tested with a username: ????????????üü
// will not work with ??éèêóòa?// Preventing your wp-site from failing in user links
// you must set WP Profiles Permalinks to UserID
// The php function used for creating links (sprintf) has no multi byte supportI can post all the code lines if you are interested.
I use wp-user-manager and I have only made preliminary tests with ultimate-member.Hello @missveronicatv and thank you for your quick reply!
I would really like to try the code, allthough you’ve only made preliminary tests.
Please post the code lines and I’ll see if I can make it work!<?php // Overrides the WordPress sanitize_user filter // to allow Swedish/Danish and English characters only // tested with a username: ????????????üü // will not work with ??éèêóòa? // Requires either WP User Manager or Ultimate Member configured for WP Profiles Permalinks to UserID // Preventing your wp-site from failing in user links you must set WP Profiles Permalinks to UserID // The php function used for creating links (sprintf) has no multi byte support (UTF8) // Warning if you have set max limit of user name length the UM plugin must use mb_strlen for counting UTF8 characters (WPUM is OK) // Install by adding or include the code to functions.php in your child theme // Modified by MissVeronica 2019-08-01 function se_dk_remove_accents( $string ) { if ( ! preg_match( '/[\x80-\xff]/', $string ) ) { return $string; } if ( seems_utf8( $string ) ) { $chars = array( // Decompositions for Latin-1 Supplement 'a' => 'a', 'o' => 'o', 'à' => 'A', 'á' => 'A', '?' => 'A', '?' => 'A', //'?' => 'A', //'?' => 'A', //'?' => 'AE', '?' => 'C', 'è' => 'E', 'é' => 'E', 'ê' => 'E', '?' => 'E', 'ì' => 'I', 'í' => 'I', '?' => 'I', '?' => 'I', 'D' => 'D', '?' => 'N', 'ò' => 'O', 'ó' => 'O', '?' => 'O', '?' => 'O', //'?' => 'O', 'ù' => 'U', 'ú' => 'U', '?' => 'U', //'ü' => 'U', 'Y' => 'Y', 'T' => 'TH', '?' => 's', 'à' => 'a', 'á' => 'a', 'a' => 'a', '?' => 'a', //'?' => 'a', //'?' => 'a', //'?' => 'ae', '?' => 'c', 'è' => 'e', 'é' => 'e', 'ê' => 'e', '?' => 'e', 'ì' => 'i', 'í' => 'i', '?' => 'i', '?' => 'i', 'e' => 'd', '?' => 'n', 'ò' => 'o', 'ó' => 'o', '?' => 'o', '?' => 'o', //'?' => 'o', //'?' => 'o', 'ù' => 'u', 'ú' => 'u', '?' => 'u', //'ü' => 'u', 'y' => 'y', 't' => 'th', '?' => 'y', //'?' => 'O', // Decompositions for Latin Extended-A 'ā' => 'A', 'ā' => 'a', '?' => 'A', '?' => 'a', '?' => 'A', '?' => 'a', '?' => 'C', '?' => 'c', '?' => 'C', '?' => 'c', '?' => 'C', '?' => 'c', '?' => 'C', '?' => 'c', '?' => 'D', '?' => 'd', '?' => 'D', '?' => 'd', 'ē' => 'E', 'ē' => 'e', '?' => 'E', '?' => 'e', '?' => 'E', '?' => 'e', '?' => 'E', '?' => 'e', 'ě' => 'E', 'ě' => 'e', '?' => 'G', '?' => 'g', '?' => 'G', '?' => 'g', '?' => 'G', '?' => 'g', '?' => 'G', '?' => 'g', '?' => 'H', '?' => 'h', '?' => 'H', '?' => 'h', '?' => 'I', '?' => 'i', 'ī' => 'I', 'ī' => 'i', '?' => 'I', '?' => 'i', '?' => 'I', '?' => 'i', '?' => 'I', '?' => 'i', '?' => 'IJ', '?' => 'ij', '?' => 'J', '?' => 'j', '?' => 'K', '?' => 'k', '?' => 'k', '?' => 'L', '?' => 'l', '?' => 'L', '?' => 'l', '?' => 'L', '?' => 'l', '?' => 'L', '?' => 'l', '?' => 'L', '?' => 'l', '?' => 'N', 'ń' => 'n', '?' => 'N', '?' => 'n', '?' => 'N', 'ň' => 'n', '?' => 'n', '?' => 'N', '?' => 'n', 'ō' => 'O', 'ō' => 'o', '?' => 'O', '?' => 'o', '?' => 'O', '?' => 'o', '?' => 'OE', '?' => 'oe', '?' => 'R', '?' => 'r', '?' => 'R', '?' => 'r', '?' => 'R', '?' => 'r', '?' => 'S', '?' => 's', '?' => 'S', '?' => 's', '?' => 'S', '?' => 's', '?' => 'S', '?' => 's', '?' => 'T', '?' => 't', '?' => 'T', '?' => 't', '?' => 'T', '?' => 't', '?' => 'U', '?' => 'u', 'ū' => 'U', 'ū' => 'u', '?' => 'U', '?' => 'u', '?' => 'U', '?' => 'u', '?' => 'U', '?' => 'u', '?' => 'U', '?' => 'u', '?' => 'W', '?' => 'w', '?' => 'Y', '?' => 'y', '?' => 'Y', '?' => 'Z', '?' => 'z', '?' => 'Z', '?' => 'z', '?' => 'Z', '?' => 'z', '?' => 's', // Decompositions for Latin Extended-B '?' => 'S', '?' => 's', '?' => 'T', '?' => 't', // Euro Sign '€' => 'E', // GBP (Pound) Sign '£' => '', // Vowels with diacritic (Vietnamese) // unmarked '?' => 'O', '?' => 'o', '?' => 'U', '?' => 'u', // grave accent '?' => 'A', '?' => 'a', '?' => 'A', '?' => 'a', '?' => 'E', '?' => 'e', '?' => 'O', '?' => 'o', '?' => 'O', '?' => 'o', '?' => 'U', '?' => 'u', '?' => 'Y', '?' => 'y', // hook '?' => 'A', '?' => 'a', '?' => 'A', '?' => 'a', '?' => 'A', '?' => 'a', '?' => 'E', '?' => 'e', '?' => 'E', '?' => 'e', '?' => 'I', '?' => 'i', '?' => 'O', '?' => 'o', '?' => 'O', '?' => 'o', '?' => 'O', '?' => 'o', '?' => 'U', '?' => 'u', '?' => 'U', '?' => 'u', '?' => 'Y', '?' => 'y', // tilde '?' => 'A', '?' => 'a', '?' => 'A', '?' => 'a', '?' => 'E', '?' => 'e', '?' => 'E', '?' => 'e', '?' => 'O', '?' => 'o', '?' => 'O', '?' => 'o', '?' => 'U', '?' => 'u', '?' => 'Y', '?' => 'y', // acute accent '?' => 'A', '?' => 'a', '?' => 'A', '?' => 'a', '?' => 'E', '?' => 'e', '?' => 'O', '?' => 'o', '?' => 'O', '?' => 'o', '?' => 'U', '?' => 'u', // dot below '?' => 'A', '?' => 'a', '?' => 'A', '?' => 'a', '?' => 'A', '?' => 'a', '?' => 'E', '?' => 'e', '?' => 'E', '?' => 'e', '?' => 'I', '?' => 'i', '?' => 'O', '?' => 'o', '?' => 'O', '?' => 'o', '?' => 'O', '?' => 'o', '?' => 'U', '?' => 'u', '?' => 'U', '?' => 'u', '?' => 'Y', '?' => 'y', // Vowels with diacritic (Chinese, Hanyu Pinyin) 'ɑ' => 'a', // macron 'ǖ' => 'U', 'ǖ' => 'u', // acute accent 'ǘ' => 'U', 'ǘ' => 'u', // caron 'ǎ' => 'A', 'ǎ' => 'a', 'ǐ' => 'I', 'ǐ' => 'i', 'ǒ' => 'O', 'ǒ' => 'o', 'ǔ' => 'U', 'ǔ' => 'u', 'ǚ' => 'U', 'ǚ' => 'u', // grave accent 'ǜ' => 'U', 'ǜ' => 'u', ); // Used for locale-specific rules $locale = get_locale(); if ( 'de_DE' == $locale || 'de_DE_formal' == $locale || 'de_CH' == $locale || 'de_CH_informal' == $locale ) { $chars['?'] = 'Ae'; $chars['?'] = 'ae'; $chars['?'] = 'Oe'; $chars['?'] = 'oe'; $chars['ü'] = 'Ue'; $chars['ü'] = 'ue'; $chars['?'] = 'ss'; } elseif ( 'da_DK' === $locale ) { //$chars['?'] = 'Ae'; //$chars['?'] = 'ae'; //$chars['?'] = 'Oe'; //$chars['?'] = 'oe'; //$chars['?'] = 'Aa'; //$chars['?'] = 'aa'; } elseif ( 'ca' === $locale ) { $chars['l·l'] = 'll'; } elseif ( 'sr_RS' === $locale || 'bs_BA' === $locale ) { $chars['?'] = 'DJ'; $chars['?'] = 'dj'; } $string = strtr( $string, $chars ); } else { $chars = array(); // Assume ISO-8859-1 if not UTF-8 $chars['in'] = "\x80\x83\x8a\x8e\x9a\x9e" . "\x9f\xa2\xa5\xb5\xc0\xc1\xc2" . "\xc3\xc4\xc5\xc7\xc8\xc9\xca" . "\xcb\xcc\xcd\xce\xcf\xd1\xd2" . "\xd3\xd4\xd5\xd6\xd8\xd9\xda" . "\xdb\xdc\xdd\xe0\xe1\xe2\xe3" . "\xe4\xe5\xe7\xe8\xe9\xea\xeb" . "\xec\xed\xee\xef\xf1\xf2\xf3" . "\xf4\xf5\xf6\xf8\xf9\xfa\xfb" . "\xfc\xfd\xff"; $chars['out'] = 'EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy'; $string = strtr( $string, $chars['in'], $chars['out'] ); $double_chars = array(); $double_chars['in'] = array( "\x8c", "\x9c", "\xc6", "\xd0", "\xde", "\xdf", "\xe6", "\xf0", "\xfe" ); $double_chars['out'] = array( 'OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th' ); $string = str_replace( $double_chars['in'], $double_chars['out'], $string ); } return $string; } add_filter ('sanitize_user', 'se_dk_sanitize_user', 10, 3); function se_dk_sanitize_user( $username, $raw_username, $strict = false ) { if( $username == $raw_username ) return $username; include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); // Verify if WP User Manager and/or Ultimate Member are active and configured for user_id permalinks if ( $wpum = is_plugin_active( 'wp-user-manager/wp-user-manager.php' ) ) { if( $wpum_permalink = get_option( 'wpum_permalink' )) { if( $wpum_permalink != 'user_id' ) return $username; } else return $username; } if ( $um = is_plugin_active( 'ultimate-member/ultimate-member.php' ) ) { if( $um_options = get_option( 'um_options' )) { $um_options = unserialise( $um_options ); if( !$um_options || $um_options['permalink_base'] != 'user_id' ) return $username; } else return $username; } if( !$wpum && !$um ) return $username; $username = wp_strip_all_tags ( $raw_username ); $username = se_dk_remove_accents( $username ); // Kill octets $username = preg_replace( '|%([a-fA-F0-9][a-fA-F0-9])|', '', $username ); // Kill entities $username = preg_replace( '/&.+?;/', '', $username ); // If strict, reduce to ASCII for max portability but save the SE/DK characters if ( $strict ) { $username = preg_replace( '/[^;\sa-zA-Z0-9 _.\-@\p{Latin}]+/u', '', $username ); // preg_replace( '|[^a-z0-9 _.\-@]|i', } $username = trim( $username ); // Consolidate contiguous whitespace $username = preg_replace( '|\s+|', ' ', $username ); return $username; }
Hello again,
Thank you so much for sending me the code!
Tried it but get some php errors when trying to register userwith? (removed personal weblinks in error msg):Fatal error: Uncaught Error: Call to undefined function unserialise() in /childtheme/functions.php:426 Stack trace: #0 /wp-includes/class-wp-hook.php(288): se_dk_sanitize_user(’userwitha’, ’userwith\xC3\xA5′, false) #1 /wp-includes/plugin.php(206): WP_Hook->apply_filters(‘userwitha’, Array) #2 /wp-includes/formatting.php(2116): apply_filters(‘sanitize_user’, ’userwitha’, ’userwith\xC3\xA5′, false) #3 /wp-content/plugins/ultimate-member/includes/core/um-actions-form.php(674): sanitize_user(’userwitha’) #4 /wp-includes/class-wp-hook.php(288): um_submit_form_errors_hook_(Array) #5 /wp-includes/class-wp-hook.php(312): WP_Hook->apply_filters(”, Array) #6 /webadress/httpd in /wp-content/themes/childtheme/functions.php on line 426
Do you think this is a quick fix? Or am I doomed to use usernames without ????
My mistake change unserialise to unserialize ie s to z
This is the code testing if you have numeric userids in UMOk, Thank you again!
Now it says:
Warning: unserialize() expects parameter 1 to be string, array given in wp-content/themes/childtheme/functions.php on line 426And the warning appears that I have unvalid characters in my username..
I have to install UM and have a look at the parameter.
Update last part of the code with this:
add_filter ('sanitize_user', 'se_dk_sanitize_user', 10, 3); function se_dk_sanitize_user( $username, $raw_username, $strict = false ) { if( $username == $raw_username ) return $username; include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); // Verify if WP User Manager and/or Ultimate Member are active and configured for user_id permalinks if ( $wpum = is_plugin_active( 'wp-user-manager/wp-user-manager.php' ) ) { if( $wpum_permalink = get_option( 'wpum_permalink' )) { if( $wpum_permalink != 'user_id' ) return $username; } else return $username; } if ( $um = is_plugin_active( 'ultimate-member/ultimate-member.php' ) ) { if( UM()->options()->get( 'permalink_base' ) != 'user_id' ) return $username; } if( !$wpum && !$um ) return $username; $username = wp_strip_all_tags ( $raw_username ); $username = se_dk_remove_accents( $username ); // Kill octets $username = preg_replace( '|%([a-fA-F0-9][a-fA-F0-9])|', '', $username ); // Kill entities $username = preg_replace( '/&.+?;/', '', $username ); // If strict, reduce to ASCII for max portability but save the SE/DK characters if ( $strict ) { $username = preg_replace( '/[^;\sa-zA-Z0-9 _.\-@\p{Latin}]+/u', '', $username ); // preg_replace( '|[^a-z0-9 _.\-@]|i', } $username = trim( $username ); // Consolidate contiguous whitespace $username = preg_replace( '|\s+|', ' ', $username ); return $username; }
Hello again!
No php error messages anymore. Sadly I still get the form-error message “invalid characters in username” when I try to register with ???.
Anyway I’m really impressed that you took the time to try to help me with this really annoying issue!Do you have UserID set here for Profile permalink base?
Yes! Also no limit of max characters in the field user_id..
- The topic ‘Allow ???/???’ is closed to new replies.