返回介绍

sanitize_user()

发布于 2017-09-11 10:19:45 字数 3431 浏览 1156 评论 0 收藏 0

sanitize_user( string $username,  bool $strict = false )

Sanitizes a username, stripping out unsafe characters.


description

Removes tags, octets, entities, and if strict is enabled, will only keep alphanumeric, _, space, ., -, @. After sanitizing, it passes the username, raw username (the username in the parameter), and the value of $strict as parameters for the ‘sanitize_user’ filter.


参数

$username

(string) (Required) The username to be sanitized.

$strict

(bool) (Optional) If set limits $username to specific characters.

Default value: false


返回值

(string) The sanitized username, after passing through filters.


源代码

File: wp-includes/formatting.php

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 );
	$username = preg_replace( '/&.+?;/', '', $username ); // Kill entities

	// 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. Default false.
	 */
	return apply_filters( 'sanitize_user', $username, $raw_username, $strict );
}

更新日志

Versiondescription
2.0.0Introduced.

相关函数

Uses

  • wp-includes/formatting.php: wp_strip_all_tags()
  • wp-includes/formatting.php: sanitize_user
  • wp-includes/formatting.php: remove_accents()
  • wp-includes/plugin.php: apply_filters()

Used By

  • wp-admin/install.php: display_setup_form()
  • wp-admin/includes/plugin-install.php: install_plugin_information()
  • wp-admin/includes/user.php: edit_user()
  • wp-includes/class-wp-user.php: WP_User::get_data_by()
  • wp-includes/pluggable.php: wp_authenticate()
  • wp-includes/user.php: register_new_user()
  • wp-includes/user.php: validate_username()
  • wp-includes/user.php: wp_insert_user()
  • wp-includes/ms-functions.php: wpmu_create_user()
  • wp-includes/ms-functions.php: wpmu_create_blog()
  • wp-includes/ms-functions.php: wpmu_validate_user_signup()
  • wp-includes/ms-functions.php: wpmu_signup_user()
  • Show 7 more used by Hide more used by

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文