sanitize_textarea_field( string $str ): string

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.

See also

Parameters

$strstringrequired
String to sanitize.

Return

string Sanitized string.

Source

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

Hooks

apply_filters( ‘sanitize_textarea_field’, string $filtered, string $str )

Filters a sanitized textarea field string.

Changelog

VersionDescription
4.7.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.