I’m debugging a problem with a third party script of ours that wordpress users use by copy / pasting a snippet of script and html into their post’s bodies like (non-real world example of course):
<script>
window.foobar = window.foobar || { hello: function(){ console.log('Hello World'); } };
window.foobar.hello();
</script>
I noticed that some installations of wordpress will wrap this in CDATA, some won’t (probably by doing some sort of DOCTYPE checking – although all themes I tested this on were using an HTML5 doctype).
Yet, when wrapping the script in CDATA the users will get bitten by the following bug: https://core.trac.wordpress.org/ticket/3670 (the closing >
is incorrectly replaced by >
) which leads to the browser ignoring the script content:
<script>// <![CDATA[ window.foobar = window.foobar || { hello: function(){ console.log('Hello World'); } }; window.foobar.hello(); // ]]></script>
I don’t own too much WP-Fu myself and googling only led me to identifying the problem as is, so my question would be: when exactly does WordPress wrap inline scripts into CDATA sections? Can the user somehow prevent this behavior? Can the user somehow work around the above bug without modifying WP core?