停止过滤 WordPress 功能 wp_insert_post [英] Stop filtering WordPress function wp_insert_post

查看:18
本文介绍了停止过滤 WordPress 功能 wp_insert_post的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须对用 WordPress 构建的网站进行一些小改动,我遇到了 wp_insert_content 函数的一些问题.此函数对输入进行消毒,完全去除一些 HTML 标签(如 )并删除其他标签上的属性.我想关闭它,并且到处都能找到 http://pp19dd.com 的链接/2010/06/unfiltered-wp_insert_post/ 解决方法是在哪里添加

'filter' =>真的

到帖子输入数组.

尽管这篇文章是 2010 年的,但我发现在 2011 年添加了额外的一行(http://web.archiveorange.com/archive/v/TDTh42SUwDEc1GFmSrvU).这行内容是:

unset( $postarr[ 'filter' ] );

and 在将输入与默认值合并之后,在清理之前立即调用.在我看来,这一行取消了上面的 'filter' => true 语句.确实,如果线在那里,就会进行消毒,如果线被取出,就会消失.

所以简单的解决方案是添加 'filter' => true 并删除函数中的额外行.但问题是我不知道该函数还在哪里使用,我想知道在 WP 代码中直接破解是否明智.WP 的更新无论如何都会恢复它.那么......有没有其他方法可以阻止此功能对输入进行消毒?

解决方案

有可能是其他插件试图清理内容,在这种情况下,删除所有过滤器是唯一的选择,请尝试以下操作:

>

remove_all_filters("content_save_pre");$post_id = wp_insert_post($post);

其他可能的过滤器标签是:

  • pre_content
  • pre_post_content
  • content_pre如果不起作用,也可以一一尝试.

I have to make a few minor changes to a website built in WordPress, and I came across some problems with the wp_insert_content function. This function sanatizes input, taking some HTML tags completely out (like ) and deleting attributes on others. I would like to switch this off, and everywhere I find a link to http://pp19dd.com/2010/06/unfiltered-wp_insert_post/ where the solution is to add

'filter' => true

to the posts input array.

This article is from 2010 though, and from what I found an extra line was added in 2011 (http://web.archiveorange.com/archive/v/TDTh42SUwDEc1GFmSrvU). This line reads:

unset( $postarr[ 'filter' ] );

and is called right after merging the input with the defaults, and before sanitizing. It seems to me that this line cancels the 'filter' => true statement above. Indeed, sanitizing happens if the line is there, and disappears if the line is taken out.

So the easy solution would be to add the 'filter' => true and delete the extra line in the function. Problem though is that I have no idea where else the function is used, and I wonder if it's smart at all to hack right in the WP code. An update of WP would restore it anyway. So ... is there any other way to stop this function from sanitizing the input?

解决方案

It is possible that some other plugin may be trying to sanitize the content, in such case remove all the filters is the only option, try the following:

remove_all_filters("content_save_pre");
$post_id = wp_insert_post($post);

Other possible filter tags are:

  • pre_content
  • pre_post_content
  • content_pre Try them one by one also if it does not work.

这篇关于停止过滤 WordPress 功能 wp_insert_post的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆