我们最近升级到 php 5.4.15,它默认没有魔术引号。是时候了:)
但事实证明,出于内部兼容性原因,wp 正在向 POST 和所有内容添加自己的斜线。
现在在很多插件中,我有一些明智的功能,如果它们是由 php 添加的,它们会去除斜杠:
function POSTGET_stripslashes_all($forced=false)
{
if(!get_magic_quotes_gpc() and !get_magic_quotes_runtime()) if(!$forced) return;
....
但是无论 php 设置如何,wp 都会添加斜线,所以无论任何设置如何,我最终都会去除斜线。问题是,如果用户想在其输入中使用文字斜杠怎么办?
如何对此产生一些意义?我不想总是去掉斜杠。你是如何处理这个问题的?当涉及到 wp 时,您会放弃并剥离所有内容吗?是否有一个很好的经验法则来说明 wp 在哪里和哪里不斜线?
最佳答案
好吧,我必须找到自己的答案。
file: wp-settings.php > function wp_magic_quotes() is called.
- wp运行时几乎包含该文件,由wp-config.php无条件包含。
- 函数调用在几乎所有事情之前,
- 但在 advanced-cache.php 之后调用
- 并且在操作 Hook do_action( 'plugins_loaded' ) 之后。
函数本身:
function wp_magic_quotes() (is in file wp-includes/load.php)
{
if(get_magic_quotes_gpc()) strip_slashes()
adds slashes to POST, GET, COOKIES and SERVER, using add_magic_quotes()
}
因此,如果您需要决定是否去除斜线,请使用:
if(!get_magic_quotes_gpc() and !function_exists('wp_magic_quotes')) do_not_strip;
这是完整的函数形式:
function POSTGET_stripslashes_all($forced=false)
{
global $POSTGET_stripslashes_all_done;
if(!get_magic_quotes_gpc() and !function_exists('wp_magic_quotes')) if(!$forced) return;//wp check
if($POSTGET_stripslashes_all_done) return;
//stripslashes
if(is_array($_POST)) $_POST=POSTGET_stripslashes_deep($_POST,$forced);
if(is_array($_GET)) $_GET=POSTGET_stripslashes_deep($_GET,$forced);
if(is_array($_REQUEST)) $_REQUEST=POSTGET_stripslashes_deep($_REQUEST,$forced);
$POSTGET_stripslashes_all_done=true;
}
function POSTGET_stripslashes_deep($value,$forced=false)
{
global $POSTGET_stripslashes_all_done;
if(!get_magic_quotes_gpc() and !function_exists('wp_magic_quotes')) if(!$forced) return $value;
if($POSTGET_stripslashes_all_done) if(!$forced) return $value;
if(is_string($value)) return stripslashes($value);
if(is_array($value))
foreach($value as $name=>$val)
$value[$name]=POSTGET_stripslashes_deep($val,$forced);
return $value;
}
关于wordpress - 如果在服务器上关闭魔术引号,wordpress 会做什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16748663/