这个问题在不同的地方已经有几次了,但我没有找到明确的答案.大多数解决方案涉及到人们在PHP.ini文件(我做过)或修改核心WP文件上禁用Magic Quotes.
无论如何,问题是这样的:为什么每次我使用$wpdb-> insert或$wpdb->更新在任何单引号之前添加斜杠.例如:
I’ve eaten strawberries becomes I\’ve eaten strawberries
以下是我使用的示例代码:
$id = $_POST['id']; $title = $_POST['title']; $message = $_POST['message']; $wpdb->update('table_name',array('id'=>$id,'title'=>$title,'message'=>$message),array('id'=>$id))
同样的问题在这里:WordPress Database Output – Remove SQL Injection Escapes,但从来没有解决过“禁用魔术报价”
在这一天度过了一天之后,答案如下:
wordpress转义在$_POST声明,而不是实际的插入,这是奇怪的.
$id = stripslashes_deep($_POST['id']); //added stripslashes_deep which removes WP escaping. $title = stripslashes_deep($_POST['title']); $message = stripslashes_deep($_POST['message']); $wpdb->update('table_name',array('id'=>$id));
这样做将意味着WP不会在任何引号之前添加斜杠.