I’ve been reading the codex at this page: http://codex.wordpress.org/Function_Reference/stripslashes_deep
The code i wrote before reading that page is this:
$data = array(
'col1' => $v['float'],
'col2' => stripslashes($v['string'])
);
$format = array( '%f', '%s' );
$wpdb->insert( 'table', $data, $format );
Basically i manually pass stripslashed values in the $data array. Now, is this code correct and secure or shall i perform a $_REQUEST = array_map( 'stripslashes_deep', $_REQUEST );
? Is there any important difference or is it the same?
If you check out the source for the
$wpdb->insert( $table, $data, $format)
method you will find this comment:so you shouldn’t need to do the SQL escape yourself on the data.
As far as I understand the process, the data inserted into the
$wpdb->insert()
method, goes through:$wpdb->prepare()
method,$wpdb->escape_by_ref()
,$wpdb->_real_escape()
, for non floating values:! is_float( $string )
,mysql_real_escape_string()
ormysqli_real_escape_string()
for WP 3.9+ with PHP 5.5+.From the PHP docs on the
mysql_real_escape_string()
function:But as stated in the Codex page you refer to, in older versions of PHP the
addslashes
can be automatically applied to the$_POST
,$_GET
and$_REQUEST
globals. The Magic Quotes feature is deprecated in PHP 5.3 and removed in 5.4.