好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

WordPress禁止没有Gravatar头像的邮箱提交评论 - Wo

WordPress禁止没有Gravatar头像的邮箱提交评论

个人博客给垃圾评论充满己经不是什么怪事了,我们经常会看到自己的博客下面的评论很乱了,下面给各位整理一个WordPress禁止没有Gravatar头像的邮箱提交评论方法,这个方法是比较有效的.

最近被垃圾评论弄烦了,有些目测是人工评论,但是带着广告链接,看着恶心,大部分没有Gravatar头像,于是本博决定阻止掉没有头像的访客正常提交评论,编辑所用主题的functions.php文件,加入下面的代码:

/*        * @author:vfhky 2013年09月11日20:23        * @param string $email 用户提交的表单中的email字段        * @return int 0:无gravatar头像; 1:有gravatar头像        **/   function  vfhky_checkgravatar( $email ) {       $email_hash  = md5( strtolower (trim( $email )));       $check_uri  =  'http://www.gravatar.com/avatar/' . $email_hash . '?d=404' ;       $headers  = @get_headers( $check_uri );       if  (!preg_match( "|200|" ,  $headers [0])) {           return  0;      }  else  {           return  1;      }  }  

本博客使用了Willin Kan大神的ajax提交评论,编辑comments-ajax.php,找到下面的代码:

if  ( get_option( 'require_name_email' ) && ! $user ->ID ) {    if  ( 6 >  strlen ( $comment_author_email ) ||  ''  ==  $comment_author  )    err( __( 'Error: please fill the required fields (name, email).' ) );  // ? wp_die 改?殄e?提示     elseif  ( !is_email( $comment_author_email ))    err( __( 'Error: please enter a valid email address.' ) );  // ? wp_die 改?殄e?提示   }    //修改为:     if  ( get_option( 'require_name_email' ) && ! $user ->ID ) {    if  ( 6 >  strlen ( $comment_author_email ) ||  ''  ==  $comment_author  )    err( __( '错误:请必须填写昵称以及邮箱。' ) );  // ? wp_die 修改提示     elseif  ( !is_email( $comment_author_email ))    err( __( '错误:请输入一个有效的电子邮箱地址。' ) );  // ? wp_die 修改提示     elseif  (vfhky_checkgravatar( $comment_author_email ) == 0)     err( __( '错误:请使用注册有Gravatar头像的邮箱留言。' ) );   }  //phpfensi.com

查看更多关于WordPress禁止没有Gravatar头像的邮箱提交评论 - Wo的详细内容...

  阅读:51次