wp_slash() WordPress Function

The wp_slash() function is used to escape a string for use in a query. It is similar to the addslashes() function, but it is specifically designed for use with WordPress databases.

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.


Top ↑

Parameters

$value

(string|array)(Required)String or array of data to slash.


Top ↑

Return

(string|array) Slashed $value.


Top ↑

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;
}


Top ↑

Changelog

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

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More