WordPress caches the Gravatar profile picture and changes it locally.

Source: Internet
Author: User
Tags php file

Create a folder in the wordpress Directory: avatar. The folder permission is 755. If you do not have the folder permission, set it to 777. This is the path to the gravatar avatar cache.
 
Set default avatar

Create a default avatar, or copy it directly in the wordpress background settings, and name it "default.jpg", which is placed in the avatar folder. I can't open it. I will provide a picture I'm using.
 
Add cache code

Copy the following code to the template's functions. php file:

The code is as follows: Copy code

Function my_avatar ($ avatar ){
$ Tmp = strpos ($ avatar, 'http ');
$ G = substr ($ avatar, $ tmp, strpos ($ avatar, "'", $ tmp)-$ tmp );
$ Tmp = strpos ($ g, 'Avatar/') + 7;
$ F = substr ($ g, $ tmp, strpos ($ g ,"? ", $ Tmp)-$ tmp );
$ W = home_url (); // $ w = get_bloginfo ('URL ');
$ E = preg_replace ('/wordpress //', '', ABSPATH). 'Avatar/'. $ f .'.jpg ';
$ T = 604800; // Set 7 days, in seconds
If (empty ($ default) $ default = $ w. '/avatar/default.jpg ';
If (! Is_file ($ e) | (time ()-filemtime ($ e)> $ t) // When the avatar does not exist or the file has been updated for more than 7 days
Copy (htmlspecialchars_decode ($ g), $ e );
Else
$ Avatar = strtr ($ avatar, array ($ g => $ w. '/avatar/'.w.f.'.jpg '));
If (filesize ($ e) <500) copy ($ default, $ e );
Return $ avatar;
 }
Add_filter ('Get _ avatar ', 'My _ avatar ');

After completing the above things, it will be OK, as set on this site.

Conclusion: in fact, it is quite good to cache Gravatar pictures locally. You can manage and maintain the items on your server. You can see that the big station has put the data on another server.

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.