Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

This is my situation. I have two plugins, one plugin will read a remote XML file and downloads content then it calls a function on another plugin to do the actual importing of posts to the WordPress database.

Now here is the problem, the second problem inserts posts using wp_insert_post method and this is a multisite implementation.

As a result, it strips div ids inside the post_content for example:

<div id="this_is_example">

Would become:

<div>

Someone suggests me to use force_filtered_html_on_import filters like this:

add_filter( 'force_filtered_html_on_import', '__return_false', 999 );

This will disable the filtering of HTML during import and will preserved the div ids inside the post_content.

I have tried adding this filter on the first plugin but it didn't work. I have a restriction to add this filter to the first plugin as the second plugin is beyond my control.

How to make this work by only adding this filter on the first plugin that do the import? This filter is not so documented by WordPress. I would appreciate any help on this one. Thanks.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

The solution that I've found is to add this line just before doing the import:

        if (function_exists('kses_remove_filters')) {
        kses_remove_filters();
        }

That will disable the kses filters responsible for stripping HTML tag inside the post_content.

I have successfully added this to the first plugin. Once this is disabled, it seems that when the import call to the second plugin has been made, it will effectively disable these filters as well.

I hope this will help anyone having an issue of filtered HTML caused by wp_insert_post.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.