wc_clean()WC 1.0

Cleans the passed data (variables) using sanitize_text_field(). Arrays are cleared recursively.

Only arrays and scalar values (numbers, strings) are processed. Non-scalar values are ignored.

No Hooks.

Return

String|Array.

Usage

wc_clean( $var );
$var(string|array) (required)
Data to sanitize.

Examples

#1 How the function works

All examples on sanitize_text_field() are relevant, e.g:

wc_clean( 'Let`s Check, <em>how</em>
the string is cleared     <br>. ' );
//> 'Let`s check, how the string is cleared .'

wc_clean( 'http://example.com/foo.php#bar' );
//> 'http://example.com/foo.php#bar'

It is also possible to process an array:

$data = [
	'say' => 'Hello,<br>user!',
	'<p>Paragraph with text</p>',
	'Plain Text',
];

wc_clean( $data );

/*
Array
(
	[say] => Hello,user!
	[0] => Paragraph with text
	[1] => Plain Text
)
*/

Code of wc_clean() WC 6.5.1

function wc_clean( $var ) {
	if ( is_array( $var ) ) {
		return array_map( 'wc_clean', $var );
	} else {
		return is_scalar( $var ) ? sanitize_text_field( $var ) : $var;
	}
}