WordPress 4.2 评论表情失效解决方法
发布:smiling 来源: PHP粉丝网 添加日期:2015-10-16 14:41:34 浏览: 评论:0
WordPress更新至4.2版本后调整了某些函数,听到最多的疑问便是评论表情都失效了,其实也不是啥太大的问题,只不过Wordpress更新至4.2以后评论表情函数名进行了变更而已,才导致了很多博客的表情全部都是叉叉,其实解决方法有很多种,今天,珞凡在这里介绍一种简单的方法帮助大家解决评论表情失效的问题.
将以下代码直接丢进主题functions.php即可:
- /**
- * Disable the emoji's
- */
- 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.
- *
- * @param array $plugins
- * @return array Difference betwen the two arrays
- */
- function disable_emojis_tinymce( $plugins ) {
- return array_diff( $plugins, array( 'wpemoji' ) );
- }
- function smilies_reset() {
- global $wpsmiliestrans;
- // don't bother setting up smilies if they are disabled
- if ( !get_option( 'use_smilies' ) )
- return;
- $wpsmiliestrans = array(
- ':mrgreen:' => 'icon_mrgreen.gif',
- ':neutral:' => 'icon_neutral.gif',
- ':twisted:' => 'icon_twisted.gif',
- ':arrow:' => 'icon_arrow.gif',
- ':shock:' => 'icon_eek.gif',
- ':smile:' => 'icon_smile.gif',
- ':???:' => 'icon_confused.gif',
- ':cool:' => 'icon_cool.gif',
- ':evil:' => 'icon_evil.gif',
- ':grin:' => 'icon_biggrin.gif',
- ':idea:' => 'icon_idea.gif',
- ':oops:' => 'icon_redface.gif',
- ':razz:' => 'icon_razz.gif',
- ':roll:' => 'icon_rolleyes.gif',
- ':wink:' => 'icon_wink.gif',
- ':cry:' => 'icon_cry.gif',
- ':eek:' => 'icon_surprised.gif',
- ':lol:' => 'icon_lol.gif',
- ':mad:' => 'icon_mad.gif',
- ':sad:' => 'icon_sad.gif',
- '8-)' => 'icon_cool.gif',
- '8-O' => 'icon_eek.gif',
- ':-(' => 'icon_sad.gif',
- ':-)' => 'icon_smile.gif',
- ':-?' => 'icon_confused.gif',
- ':-D' => 'icon_biggrin.gif',
- ':-P' => 'icon_razz.gif',
- ':-o' => 'icon_surprised.gif',
- ':-x' => 'icon_mad.gif',
- ':-|' => 'icon_neutral.gif',
- ';-)' => 'icon_wink.gif',
- // This one transformation breaks regular text with frequency.
- // '8)' => 'icon_cool.gif',
- '8O' => 'icon_eek.gif',
- ':(' => 'icon_sad.gif',
- ':)' => 'icon_smile.gif',
- ':?' => 'icon_confused.gif',
- ':D' => 'icon_biggrin.gif',
- ':P' => 'icon_razz.gif',
- ':o' => 'icon_surprised.gif',
- ':x' => 'icon_mad.gif',
- ':|' => 'icon_neutral.gif',
- ';)' => 'icon_wink.gif',
- ':!:' => 'icon_exclaim.gif',
- ':?:' => 'icon_question.gif',
- ); //phpfensi.com
- }
- smilies_reset();
最后,想补充的是,Wordpress 4.2修改了translate_smiley函数,使得输出的表情带样式(style),具体为style="height: 1em; max-height: 1em;",这可能会对我们的表情产生影响(我的是被压扁了),因为这个函数本身没有过滤器,所以无法添加过滤,对输出再解码也影响性能,只能修改源文件,来达到目的,具体位置在/wp-includes/formatting.php的第2114行,如下:
- return sprintf( '<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', esc_url( $src_url ), esc_attr( $smiley ) );
- //修改为:
- return sprintf( '<img src="%s" alt="%s" class="wp-smiley" />', esc_url( $src_url ), esc_attr( $smiley ) );
其实就是删除这个样式,这样就不会对我们现有的表情产生任何影响了.
Tags: WordPress评论 WordPress表情
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)