首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何修改sanitize_user WordPress函数以接受西里尔文用户名

如何修改sanitize_user WordPress函数以接受西里尔文用户名
EN

Stack Overflow用户
提问于 2021-01-17 23:04:15
回答 1查看 182关注 0票数 0

原始函数:

代码语言:javascript
复制
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 );

我想修改它,以接受用户名在西里尔(塞尔维亚语)时,用户执行注册。

塞尔维亚文西里尔文字母表абвгдђежзијклљмнњопрстћуфхцчџшАБВГДЂЕЖЗИЈКЛЉМНЊОПРСТЋУФХЦЧЏШ

EN

回答 1

Stack Overflow用户

发布于 2021-01-18 00:03:43

代码语言:javascript
复制
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 );

尝试一下-使用WP 5.6时测试正常

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65762243

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档