原功能:
function sanitize_user( $username, $strict = false ) {
$raw_username = $username;
$username = wp_strip_all_tags( $username );
$username = 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.
if ( $strict ) {
$username = preg_replace( '|[^a-z0-9 _.-@]|i', '', $username );
}
$username = trim( $username );
// Consolidate contiguous whitespace.
$username = preg_replace( '|s+|', ' ', $username );
/**
* Filters a sanitized username string.
*
* @since 2.0.1
*
* @param string $username Sanitized username.
* @param string $raw_username The username prior to sanitization.
* @param bool $strict Whether to limit the sanitization to specific characters.
*/
return apply_filters( 'sanitize_user', $username, $raw_username, $strict );
我想修改它接受用户名在西里尔字母(塞尔维亚)当用户执行注册。
塞尔维亚西里尔字母абвгдђежзијклљмнњопрстћуфхцчџшАБВГДЂЕЖЗИЈКЛЉМНЊОПРСТЋУФХЦЧЏШ
function mujuonly_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 Cyrillic characters for maximum portability.
if ( $strict )
$username = preg_replace( '|[^a-zа-я0-9 _.-@]|iu', '', $username );
$username = trim( $username );
// Consolidate contiguous whitespace
$username = preg_replace( '|s+|', ' ', $username );
return $username;
}
add_filter( 'sanitize_user', 'mujuonly_sanitize_user', 10, 3 );
Try this -在WP 5.6下测试OK