php - 防止 WordPress 的默认输入清理
问题描述
每当我从一个<textarea>
或一个文件中获得输入时input
,WordPress 都会清理我的输入并转义所有特殊字符。如何禁用此功能?例如,如果我有以下接受 C++ 代码(如cout<<"hello world";
WordPress)的 html 代码,会将其转换为cout<<\"hello world\";
.
<!--HTML code-->
<form action="/action.php" method="post">
<input type="text" name="mycode" value="cout<<'hello world';">
<input type="submit" value="Submit">
</form>
.
<?php
//PHP code for action.php file
echo $_POST['mycode'];//This output will have all the special characters escaped
//I need this to give me the original text entered by the user without /s.
?>
我正在使用 WordPress 版本 5.7.2。任何时候我使用像 \, ', "
他们这样的特殊字符都会\
出现在他们面前。我已经尝试过使用不同的 WordPress 主题,结果仍然相同。如果我用stripcslashes($_POST['mycode'])
这个得到这些\
。但是想知道是否有办法阻止 WordPress 从一开始就这样做。下面显示了我得到的输入和输出的图像。
解决方案
这是一个非常简单的 hack-y 想法
在 WP 的顶部/index.php
,在 WP 贪婪地控制您的传入数据之前,添加以下行:
$_SPOST = null;
if (isset($_SERVER['REQUEST_METHOD']) && strtoupper($_SERVER['REQUEST_METHOD']) === 'POST') {
$_SPOST = $_POST;
}
然后,只要您知道您会将代码内容传回浏览器
<?php
//PHP code for action.php file
echo $_SPOST['mycode'];//This output will have all the special characters escaped
//I need this to give me the original text entered by the user without /s.
?>
但是等等,还有更多......我们可以在 wordpress 生态系统中重新连接,并在我们的帖子被修改和清理后转换我们的帖子。
这个页面给了我使用parse_request的想法,它会在当前请求的所有查询变量都被解析后触发。
function use_spost() {
if (isset($_SPOST)) $_POST = $_SPOST;
}
add_action('parse_request', 'use_spost', 1);
推荐阅读
- c# - 为什么前置摄像头的像素强度始终与 0.5f 相同(Frame.LightEstiamation.PixelIntesity)
- java - JUnit DisabledOnOs 注释不起作用
- java - JHipster 中外部 API 的访问控制策略
- java - 如何检测用户是否拖动 PIP 窗口(向下拖动以关闭)?
- android - 我如何使所有应用程序从右到左接收一个部分?以及使这部分没有显示在 rtl 语言上的问题是什么?
- python - 一列 0 到 100 的 DataFrame
- java - 如何从 Flux (Spring Reactor) 中的项目生成项目
- ios - 应用程序仅在通过 Xcode 运行时运行,当我尝试在与 Mac 断开连接的设备上运行它时它不起作用
- excel - 获取上次更改/导入 Excel 中的模块的日期
- nfs - 是否可以在 PCFDev 中启用 NFS 服务?