Ok, so I have a feed which is used to create posts on Wordpress.
At the bottom of the content tag, there is a simple Google Analytics script which sends a page view to Google. This all works fine when there isn't an "'" in the title tag but when there is an "'" it gets unescaped.
The feed pipes down this:
<script type="text/javascript"><!--
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXXX', 'auto', {'name': 'feed'});
ga('feed.set', 'referrer', location.origin);
ga('feed.send', 'pageview', { 'location': location.href, 'page': (location.pathname + location.search + location.hash), 'title': 'This is my title \'with an \' in it'});
//--></script>
Which gets changed to this:
<script type="text/javascript"><!--
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXXX', 'auto', {'name': 'feed'});
ga('feed.set', 'referrer', location.origin);
ga('feed.send', 'pageview', { 'location': location.href, 'page': (location.pathname + location.search + location.hash), 'title': 'This is my title 'with an ' in it'});
//--></script>
Which obviously causes me a syntax error because of the title string.
I have kses set to allow script tags, and I can manually add in the escape character to the javascript string in the wordpress content editor.
I have also added a small debugger to the wp_insert_post() method which shows that the content is fine prior to the insert statement after being sanitized etc. But then straight after save is changed?
Is there a default after content save filter which could be causing me this issue?
Thanks in advance