Wordpress prohibits comments from visitors without Gravatar portraits

Source: Internet
Author: User
Tags comments valid email address

1 Why do visitors without Gravatar portraits be restricted?

A few days ago, bloggers have been wondering whether to restrict users without gravatar portraits to post messages on their blogs for three reasons:

1. The blog uses the wordpress program, and Gravatar was acquired by Automattic as early as 07 years ago and carried forward on the wp program. Therefore, wp blogs and gravatar portraits are inherently a pair, of course, they must be together.

2. Shield advertisements. Many spamers do not have gravatar portraits. If you do not have a gravatar profile, a considerable portion of spam ads are filtered out. By far, the plug-in has made great contributions to many advertisers.

3. Block meaningless comments.

Generally, visitors who do not have a gravatar profile picture will not be active in the blog. Most of them are looking for you if you have any problems. If you solve them, you just need to leave. I have a deep understanding. I have previously written an invitation code for the official forum of mobile Yi. Many people don't even have a thank you after getting the invitation code. A blog is a platform for communication. It makes no sense to lose interaction with users. Therefore, in order to improve the overall quality of the blog, we need to block this part of the visitor.

Next, let's talk about how to implement "wordpress restricts comments from visitors who do not have a Gravatar profile picture:

2. Function for determining whether a Gravatar profile is available

Add the following function to functions. php to determine whether the message recipient has a gravatar profile picture based on the submitted email field. Another way is.

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/'. $ email_hash .'? D = 404 ';
$ Headers = @ get_headers ($ check_uri );
If (! Preg_match ("| 200 |", $ headers [0]) {
Return 0;
    }
Else {return 1 ;}
    }

3 Call the judgment function in comments-ajax.php

After the gravatar Avatar judgment function is completed, you can call it in the comments-ajax.php file of Willin Kan. In the 90 rows of the file, add the judgment function to the original code for calling.

   

The code is as follows: Copy code
/*
* @ Author: vfhky September 11, 2013
* @ Param string $ comment_author_email the email field in the form submitted by the user
**/
If (! $ User-> ID ){
If (6> strlen ($ comment_author_email) | ''= $ comment_author)
Err (_ ('prompt: you must enter a nickname and email. '));
Elseif (! Is_email ($ comment_author_email ))
Err (_ ('prompt: enter a valid email address. '));
Elseif (vfhky_checkgravatar ($ comment_author_email) = 0)
Err (_ ('use the Gravatar profile picture to leave a message. '));
    }

4 Postscript

Wordpress restricts comments from visitors who do not have a Gravatar profile picture

 

In two simple steps, you can restrict comments submitted by visitors without the Gravatar profile picture. The final effect is shown in the figure above. Of course, this function can also be implemented using jquery. However, once the user's browser shields js, it will be ineffective. Therefore, the server is considered to be more secure and reliable, although the consumption of additional resources is increased.

 

Related Article

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.