W3cubDocs

/WordPress

wp_slash( string|array $value )

Add slashes to a string or array of strings.

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|array) (Required) String or array of strings to slash.

Return

(string|array) Slashed $value

Source

File: wp-includes/formatting.php

function wp_slash( $value ) {
	if ( is_array( $value ) ) {
		foreach ( $value as $k => $v ) {
			if ( is_array( $v ) ) {
				$value[ $k ] = wp_slash( $v );
			} else {
				$value[ $k ] = addslashes( $v );
			}
		}
	} else {
		$value = addslashes( $value );
	}

	return $value;
}

Changelog

Version Description
3.6.0 Introduced.

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