I've written a custom plugin to send data via a form to a personal database, different from the WP one. Everything is working fine except the fact that when you write a name, for example D'ALESSANDRO, it's saved as D\'ALESSANDRO.


It seems that adding stripslashes_deep() before $_POST is working.

$custom_field = sanitize_text_field(stripslashes_deep($_POST[custom_field]))

Can this be unsafe?

This is how I'm sending data to database:

$custom_field = sanitize_text_field($_POST[custom_field])
if ( count($reg_errors->get_error_messages()) < 1) {
    $userdata = array(
    'id_locality'   =>  $custom_field
    $where_data = array(
    $pldb = new wpdb('user', 'pwd', 'db', 'localhost');
    $update_table = $pldb->update('table',$userdata,$where_data);

I need to save data into the database without the "\", I can't sort this when printing it.

How can I do this?

  • Use stripslashes() function after reading the data it will remove the extra slashes. – M-R Mar 24 '15 at 10:34
  • First of all thanks for the reply. You mean, save data with salshes into the database, and then use stripslashes() when printing data to the php page? In this case, I can't do this, for various reasons data has to be saved in the database directly without the extra slashes. – testermaster Mar 24 '15 at 10:37
  • To explain, I can send data to this database also via another form which uses htmlpurifier, and it's saving data into the database without the slashes, I need data to be saved in the same way. – testermaster Mar 24 '15 at 10:42
  • Noticed that the other form also uses $this->db->escape, it's a codeigniter function. I need to do things like this with a wordpress form, is this possible? – testermaster Mar 24 '15 at 11:00
  • Post updated with possible solution! – testermaster Mar 24 '15 at 11:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.