How can I stop wp_update_post messing up HTML example code?

It was https://wordpress.org/plugins/syntaxhighlighter/ plugin’s fault. There are some functions in it that have something to do with this, namely encode_shortcode_contents_slashed_noquickedit, encode_shortcode_contents_callback.

Now I replaced it to https://wordpress.org/plugins/crayon-syntax-highlighter/ but by the time I confirmed it was the other plugin’s fault I had already written a solution.

function wpse190396_insert_post_data($data, $postarr){
    if($postarr['filter'] == 'db'
        && ($data['post_type'] == 'fix' || $data['post_type'] == 'faq')
        && (strpos($data['post_content'],'<') !== false
            || strpos($data['post_content'],' ') !== false
            || strpos($data['post_content'],'>') !== false
            )){
        $data['post_content'] = htmlspecialchars_decode($data['post_content']);
    }
    return $data;
}

add_action( 'wp_insert_post_data', 'wpse190396_insert_post_data', 10, 2 );

Leave a Comment