php - 如何修改 sanitize_user WordPress 函数以接受西里尔文的用户名
问题描述
原始功能:
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 );
试试这个 -使用 WP 5.6 测试正常
推荐阅读
- mysql - sql:选择 * 和最小值,没有过滤行
- c++ - C++ 简化类/OOP 方法
- kubernetes - 并行 pod 的 subPathExpr
- javascript - 单击色板时如何更改特色图像?
- elasticsearch - 在 idex 中查找短语
- vue.js - 如何在 v-textarea 中隐藏滚动条?
- python - RNN 带或不带循环:每个输出的含义?
- python - Cisco WebEx:使用 Python 2.7 为一组新令牌生成新代码时出现问题
- php - 如何在 laravel 版本 5.0.35 中配置任何 restful api 包,如 laravel/passort 或 dingo/api(*没有作曲家)
- html - 是否有任何 CSS 代码来定位图像,如下所示但也响应屏幕尺寸?