WordPress prohibits you from submitting comments in a mailbox without a Gravatar Avatar

Source: Internet
Author: User
Tags php file strlen valid email address

Recently, spam comments have become annoying. Some of the projects are manual comments, but with ad links, they look disgusting. Most of them do not have Gravatar portraits. Therefore, Benbo decided to prevent visitors without portraits from submitting comments normally,
Edit the functions. Php file of the topic and add the following code:

The code is as follows: Copy code
/*
* @ Author: vfhky September 11, 2013
* @ Param string $ email the email field in the form submitted by the user
* @ Return int 0: No gravatar Avatar; 1: gravatar Avatar
**/
Function vfhky_checkgravatar ($ email ){
$ Email_hash = md5 (strtolower (trim ($ email )));
$ Check_uri = 'http: // www.gravatar.com/avatar/'.w.email_hash .'? D = 404 ';
$ Headers = @ get_headers ($ check_uri );
If (! Preg_match ("| 200 |", $ headers [0]) {
Return 0;
} Else {
Return 1;
    }
}

This blog uses Willin Kan's great God ajax to submit comments, edit the comments-ajax.php, find the following code:

The code is as follows: Copy code

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 change? Else e? Prompt
Elseif (! Is_email ($ comment_author_email ))
Err (_ ('Error: please enter a valid email address .'));//? Wp_die change? Else e? Prompt
}

To:

If (get_option ('require _ name_email ')&&! $ User-> ID ){
If (6> strlen ($ comment_author_email) | ''= $ comment_author)
Err (_ ('error: Enter the nickname and email address. '));//? Wp_die change? Else e? Prompt
Elseif (! Is_email ($ comment_author_email ))
Err (_ ('error: enter a valid email address. '));//? Wp_die change? Else e? Prompt
Elseif (vfhky_checkgravatar ($ comment_author_email) = 0)
Err (_ ('error: please use the email address registered with the Gravatar avatar to leave a message. '));
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.