Stop filtering WordPress function wp_insert_post

I need to make a few minor changes to a site created in WordPress, and I ran into some problems with the wp_insert_content function. This function sanitizes input by completely eliminating some HTML tags (for example) and removing the attributes of others. I would like to disable this, and everywhere I find a link to http://pp19dd.com/2010/06/unfiltered-wp_insert_post/ where the solution is to add

'filter' => true 

into the message input array.

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

 unset( $postarr[ 'filter' ] ); 

and is called immediately after merging the input with the default values ​​and before disinfection. It seems to me that this line cancels the above 'filter' => true statement. Indeed, disinfection occurs if the line is there, and disappears if the line is taken out.

Thus, a simple solution would be to add "filter" => true and remove the extra line in the function. The problem is that I have no idea where the function is still used, and I am wondering if it is really wise to hack in WP code. Updating WP will restore it anyway. So ... is there any other way to stop this function from disinfecting the entrance?

+6
source share
2 answers

It is possible that some other plugins may try to sanitize the content, in which case removing all filters is the only option, try the following:

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

Other possible filter tags:

  • pre_content
  • pre_post_content
  • content_pre Try them one by one if that doesn't work.
+6
source

I am also in the process of importing messages with s in the content body. I searched all morning for a solution, there were some discussions on this topic. until

 kses_remove_filters(); 

Did nothing for me, did not comment on these two lines:

 unset( $postarr[ 'filter' ] ); // overrides 'filter' => true since 3.0 i guess $postarr = sanitize_post($postarr, 'db'); 

in wp_insert_post () in post.php (defaults to line 2704).

There is another interesting bit on line 2874:

 $data = apply_filters('wp_insert_post_data', $data, $postarr); 

which seems to be the source of our problems, but I’m too much a beginner to figure it out on my own.

really, really, desperately need help! oh, and I can’t comment, sorry for the effect of spam. I would like to leave this thread open and find a solution.

I think this worked before I posted it, but the content that I imported already had HTML tags, the easiest way would be to manually overwrite the content after inserting the message, but this only works for sandboxes or for import

 $wpdb->update($wpdb->posts, array("post_content"=>$content->content), array("ID"=>$postid), array("%s"), array("%d")); 

anyway,

 remove_all_filters("content_save_pre"); 

did the trick!

0
source

Source: https://habr.com/ru/post/959476/


All Articles