W3cubDocs

/WordPress

wp_slash( string|string[] $value )

Add slashes to a string or array of strings, in a recursive manner.

Description

This should be used when preparing data for core API that expects slashed data. This should not be used to escape data going directly into an SQL query.

Parameters

$value

(string|string[]) (Required) String or array of strings to slash.

Return

(string|string[]) Slashed $value.

Source

File: wp-includes/formatting.php

function wp_slash( $value ) {
	if ( is_array( $value ) ) {
		$value = array_map( 'wp_slash', $value );
	}

	if ( is_string( $value ) ) {
		return addslashes( $value );
	}

	return $value;
}

Changelog

Version Description
5.5.0 Non-string values are left untouched.
3.6.0 Introduced.

© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_slash