Warning: Trying to access array offset on value of type bool in /www/wwwroot/zklhy.com/wp-content/themes/twentyfifteen/functions.php on line 544

Warning: Trying to access array offset on value of type bool in /www/wwwroot/zklhy.com/wp-content/themes/twentyfifteen/functions.php on line 553

wordpress建设 支持中文用户名的简单方法

不解释 收起来  这次突然需要用了 才想起来 还好我以前用过 知道这个东西的存在 不然那就不好搞了  哈哈! 开头纯属搞笑

直接上东西吧 这东西直接加在主题functions.php文件里面就好了 下面是代码:

function ludou_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-z\p{Han}0-9 _.\-@]|iu', '', $username);
  }

  $username = trim( $username );
  // Consolidate contiguous whitespace
  $username = preg_replace( '|\s+|', ' ', $username );

  return $username;
}

add_filter ('sanitize_user', 'ludou_sanitize_user', 10, 3);

 

发表回复