wp_slash( string|array $value )

Adds slashes to a string or recursively adds slashes to strings within an array.


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

(Required) String or array of data to slash.


Return

(string|array) Slashed $value, in the same type as supplied.


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

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