将以下php代码复制到当前主题目录下的functions.php中,即可让WordPress支持使用中文用户名注册和登录:
1 |
function mobantu_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 // 网上很多教程都是直接将$strict赋值false, // 这样会绕过字符串检查,留下隐患 if ($strict) { $username = preg_replace ('|[^a-zp{Han}0-9 _.-@]|iu', '', $username); } $username = trim( $username ); // Consolidate contiguous whitespace $username = preg_replace( '|s+|', ' ', $username ); return $username; } add_filter ('sanitize_user', 'mobantu_sanitize_user', 10, 3); |
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。