I am attempting to publish HTML generated from an external party within Wordpress, but I am getting very inconsistent results with style
attribute on all HTML elements, in that if I programmatically update the post the style
attributes get removed, but if I publish the same HTML via the editor it remains untouched. Debugging so far it looks like the kses
filter is what is performing the actual stripping
Original HTML:
<div class="container-fluid " style="background-image:url('https://localhost/app/uploads/2018/08/315.png');"></div>
When submitted programmatically it becomes:
<div class="container-fluid "></div>
The code that does the submitting (modified to be clearer example)
$body = <<<EOT
<div class="container-fluid " style="background-image:url('https://localhost/app/uploads/2018/08/315.png');"></div>
EOT;
$new_post = [
'ID' => 70,
'post_title' => 'Example',
'post_content' => $body,
'post_type' => 'post',
'post_status' => 'draft'
];
$success = wp_update_post($new_post, true);
The goal is to avoid the stripping in a normal environment
Envionment:
- Wordpress 4.9.6
- No additional plugins outside of the one this code resides in
- Default theme