sanitize_textarea_field() WordPress Function

The sanitize_textarea_field() function is a sanitization and validation function for textareas. The function first strips all tags from the textarea, then it runs the text through the wp_check_invalid_utf8() function to check for invalid UTF8 characters. Finally, the function strips any extra whitespace from the textarea. This function is useful for ensuring that textareas contain only valid UTF8 characters and no extra whitespace.

sanitize_textarea_field( string $str ) #

Sanitizes a multiline string from user input or from the database.


Description

The function is like sanitize_text_field(), but preserves new lines (\n) and other whitespace, which are legitimate input in textarea elements.

Top ↑

See also


Top ↑

Parameters

$str

(string)(Required)String to sanitize.


Top ↑

Return

(string) Sanitized string.


Top ↑

Source

File: wp-includes/formatting.php

function sanitize_textarea_field( $str ) {
	$filtered = _sanitize_text_fields( $str, true );

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


Top ↑

Changelog

Changelog
VersionDescription
4.7.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More