你好,游客 登录 注册 搜索
背景:
阅读新闻

WordPress更新后移除头部window._wpemojiSettings这样的emjo表情

[日期:2016-09-14] 来源:本站整理  作者:www.zhaozy.com [字体: ]
WordPress更新到新的版本后,像4.2以后的版本,好像都会自动在页面的头部落增加window._wpemojiSettings这样的 emjo表情加载,其实很多站点是用不上的,像部落的网站,是禁止加载这样的表情的,没有多少意义.对于这个功能,我们可以通过在源代码的方式下查看,显 示为一长串的页面加载符,更需要补充的是,加上 GFW 的强大力量,我们也不知道哪一天就无法打开,毕竟是加载在国外的服务器上.所以我们很有必要去移除这一功能.

显示的这个JS内容如下:
 

    <script type="text/javascript">  
                window._wpemojiSettings = {"baseUrl":"httpss:\/\/s.w.org\/images\/core\/emoji\/72x72\/","ext":".png","source":{"concatemoji":"https:\/\/www.zhaozy.com\/wp-includes\/js\/wp-emoji-release.min.js?ver=4.5.2"}};  
                !function(a,b,c){function d(a){var c,d,e,f=b.createElement("canvas"),g=f.getContext&&f.getContext("2d"),h=String.fromCharCode;if(!g||!g.fillText)return!1;switch(g.textBaseline="top",g.font="600 32px Arial",a){case"flag":return g.fillText(h(55356,56806,55356,56826),0,0),f.toDataURL().length>3e3;case"diversity":return g.fillText(h(55356,57221),0,0),c=g.getImageData(16,16,1,1).data,d=c[0]+","+c[1]+","+c[2]+","+c[3],g.fillText(h(55356,57221,55356,57343),0,0),c=g.getImageData(16,16,1,1).data,e=c[0]+","+c[1]+","+c[2]+","+c[3],d!==e;case"simple":return g.fillText(h(55357,56835),0,0),0!==g.getImageData(16,16,1,1).data[0];case"unicode8":return g.fillText(h(55356,57135),0,0),0!==g.getImageData(16,16,1,1).data[0]}return!1}function e(a){var c=b.createElement("script");c.src=a,c.type="text/javascript",b.getElementsByTagName("head")[0].appendChild(c)}var f,g,h,i;for(i=Array("simple","flag","unicode8","diversity"),c.supports={everything:!0,everythingExceptFlag:!0},h=0;h<i.length;h++)c.supports[i[h]]=d(i[h]),c.supports.everything=c.supports.everything&&c.supports[i[h]],"flag"!==i[h]&&(c.supports.everythingExceptFlag=c.supports.everythingExceptFlag&&c.supports[i[h]]);c.supports.everythingExceptFlag=c.supports.everythingExceptFlag&&!c.supports.flag,c.DOMReady=!1,c.readyCallback=function(){c.DOMReady=!0},c.supports.everything||(g=function(){c.readyCallback()},b.addEventListener?(b.addEventListener("DOMContentLoaded",g,!1),a.addEventListener("load",g,!1)):(a.attachEvent("onload",g),b.attachEvent("onreadystatechange",function(){"complete"===b.readyState&&c.readyCallback()})),f=c.source||{},f.concatemoji?e(f.concatemoji):f.wpemoji&&f.twemoji&&(e(f.twemoji),e(f.wpemoji)))}(window,document,window._wpemojiSettings);  
            </script>

我们可以在wordpress后台所在的主题functions.php加入如下代码即可:
 

    //禁用WordPress Emoji表情  from www.zhaozy.com  
    function disable_emojis() {  
    remove_action( 'wp_head', 'print_emoji_detection_script', 7 );  
    remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );  
    remove_action( 'wp_print_styles', 'print_emoji_styles' );  
    remove_action( 'admin_print_styles', 'print_emoji_styles' );  
    remove_filter( 'the_content_feed', 'wp_staticize_emoji' );  
    remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );  
    remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );  
    add_filter( 'tiny_mce_plugins', 'disable_emojis_tinymce' );  
    }  
    add_action( 'init', 'disable_emojis' );  
    /**  
    * Filter function used to remove the tinymce emoji plugin.  
    */
    function disable_emojis_tinymce( $plugins ) {  
    if ( is_array( $plugins ) ) {  
    return array_diff( $plugins, array( 'wpemoji' ) );  
    } else {  
    return array();  
    }  
    }

接下来,我们再查看网页的源代码,就会发现之前显示的window._wpemojiSettings这样的emjo表情,已经被成功移除了.
本文评论   [发表评论]   全部评论 (0)
站长推荐
热门评论