wordpress如何让用户发布文章 wordpress怎么让手机和电脑一样
创始人
2025-01-12 20:02:18
:

  今天介绍新的方法,借鉴了wp-includes/formatting.php中sanitize_user函数的写法,同样是将以下php代码复制到当前主题目录下的functions.php中,即可让WordPress支持使用中文用户名注册和登录:

  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);

相关内容

热门资讯

谷歌投入3000万美元发布AI... 11月12日,谷歌与旗下DeepMind在伦敦共同举办“人工智能学习论坛”,邀请来自全球的教育专家、...
AI概念,突发回调! 当地时间11月11日,美股三大指数表现分化,截至收盘,道指涨1.18%,报47927.96点,收盘价...
当AI硬件开始“反杀”手机 2025年11月6日的科大讯飞全球开发者节现场,董事长刘庆峰做了一个对比演示: 在高噪音和远距离两种...
原创 北... 小火锅赛道已迈入以品质升级为核心的洗牌期。 昔日“小火锅排队王”桃娘下饭小火锅的北京门店已经全关...
AMD确认Zen6 Medus... 快科技11月12日消息,在AMD公司金融分析师日活动上,AMD正式确认了其下一代客户端CPU和GPU...