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. ')); } |