_sanitize_text_fields
Internal helper function to sanitize a string from user input or from the db.
Description
Parameters (2)
- 0. $str
- The str.
- 1. $keep_newlines — Optional. (bool) =>
false
- The keep newlines.
Usage
if ( !function_exists( '_sanitize_text_fields' ) ) { require_once ABSPATH . PLUGINDIR . 'google-analytics-for-wordpress-by-monsterinsights/includes/admin/settings/settings-api.php'; } // The str. $str = null; // The keep newlines. $keep_newlines = false; // NOTICE! Understand what this does before running. $result = _sanitize_text_fields($str, $keep_newlines);
Defined (1)
The function is defined in the following location(s).
- /includes/admin/settings/settings-api.php
- function _sanitize_text_fields( $str, $keep_newlines = false ) {
- $filtered = wp_check_invalid_utf8( $str );
- if ( strpos($filtered, '<') !== false ) {
- $filtered = wp_pre_kses_less_than( $filtered );
- // This will strip extra whitespace for us.
- $filtered = wp_strip_all_tags( $filtered, false );
- // Use html entities in a special case to make sure no later
- // newline stripping stage could lead to a functional tag
- $filtered = str_replace("<\n", "<\n", $filtered);
- }
- if ( ! $keep_newlines ) {
- $filtered = preg_replace( '/[\r\n\t ]+/', ' ', $filtered );
- }
- $filtered = trim( $filtered );
- $found = false;
- while ( preg_match('/%[a-f0-9]{2}/i', $filtered, $match) ) {
- $filtered = str_replace($match[0], '', $filtered);
- $found = true;
- }
- if ( $found ) {
- // Strip out the whitespace that may now exist after removing the octets.
- $filtered = trim( preg_replace('/ +/', ' ', $filtered) );
- }
- return $filtered;
- }