sanitize_text_field() - WordPress 函数参考中文文档

返回介绍

sanitize_text_field()

发布于 2017-09-11 字数4358 浏览 861 评论 0

sanitize_text_field( string $str )

清理用户输入或者从数据库中获取的字符串。


描述

  • Checks for invalid UTF-8,
  • Converts single < characters to entities
  • Strips all tags
  • Removes line breaks, tabs, and extra whitespace
  • Strips octets

检查是否合法的 UTF-8 字符,将 < 转换成 HTML 实体,去掉所有标签,删除所有换行符,占位符,以及额外的空格,去掉八位字节。


参数

$str
(string) (required) 将要清理的字符串。
Default: None

返回值

清理之后的字符串


源代码

File: wp-includes/formatting.php

function sanitize_text_field( $str ) {
	$filtered = _sanitize_text_fields( $str, false );

	/**
	 * Filters a sanitized text field string.
	 *
	 * @since 2.9.0
	 *
	 * @param string $filtered The sanitized string.
	 * @param string $str      The string prior to being sanitized.
	 */
	return apply_filters( 'sanitize_text_field', $filtered, $str );
}

更新日志

Version 描述
2.9.0 Introduced.

More Information

Basic Usage

<?php sanitize_text_field( $str ) ?>

相关函数

Uses

  • wp-includes/formatting.php:_sanitize_text_fields()
  • wp-includes/formatting.php:sanitize_text_field
  • wp-includes/plugin.php:apply_filters()

Used By

  • wp-includes/rest-api.php:rest_sanitize_value_from_schema()
  • wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php:WP_REST_Attachments_Controller::create_item()
  • wp-admin/includes/ajax-actions.php:wp_ajax_delete_plugin()
  • wp-includes/customize/class-wp-customize-nav-menu-setting.php:WP_Customize_Nav_Menu_Setting::sanitize()
  • wp-includes/customize/class-wp-customize-nav-menu-item-setting.php:WP_Customize_Nav_Menu_Item_Setting::sanitize()
  • wp-includes/class-wp-customize-nav-menus.php:WP_Customize_Nav_Menus::ajax_search_available_items()
  • wp-admin/includes/ajax-actions.php:wp_ajax_update_plugin()
  • wp-admin/includes/class-wp-press-this.php:WP_Press_This::save_post()
  • wp-signup.php:validate_another_blog_signup()
  • wp-signup.php:validate_blog_signup()
  • wp-admin/includes/user.php:edit_user()
  • wp-admin/includes/media.php:media_handle_upload()
  • wp-admin/includes/post.php:edit_post()
  • wp-admin/includes/ajax-actions.php:wp_ajax_save_attachment()
  • wp-includes/class-wp-customize-manager.php:WP_Customize_Manager::save()
  • wp-includes/widgets/class-wp-nav-menu-widget.php:WP_Nav_Menu_Widget::update()
  • wp-includes/widgets/class-wp-widget-recent-comments.php:WP_Widget_Recent_Comments::update()
  • wp-includes/widgets/class-wp-widget-tag-cloud.php:WP_Widget_Tag_Cloud::update()
  • wp-includes/widgets/class-wp-widget-categories.php:WP_Widget_Categories::update()
  • wp-includes/widgets/class-wp-widget-categories.php:WP_Widget_Categories::form()
  • wp-includes/widgets/class-wp-widget-recent-posts.php:WP_Widget_Recent_Posts::update()
  • wp-includes/widgets/class-wp-widget-calendar.php:WP_Widget_Calendar::update()
  • wp-includes/widgets/class-wp-widget-calendar.php:WP_Widget_Calendar::form()
  • wp-includes/widgets/class-wp-widget-text.php:WP_Widget_Text::update()
  • wp-includes/widgets/class-wp-widget-search.php:WP_Widget_Search::update()
  • wp-includes/widgets/class-wp-widget-archives.php:WP_Widget_Archives::update()
  • wp-includes/widgets/class-wp-widget-archives.php:WP_Widget_Archives::form()
  • wp-includes/widgets/class-wp-widget-meta.php:WP_Widget_Meta::update()
  • wp-includes/widgets/class-wp-widget-meta.php:WP_Widget_Meta::form()
  • wp-includes/widgets/class-wp-widget-pages.php:WP_Widget_Pages::update()
  • wp-includes/post-template.php:wp_page_menu()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!