dsgsdg206050 2016-05-04 16:39
浏览 30

Wordpress内联Javascript Unescape

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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?