| 1 |
== Gravatars == |
|---|
| 2 |
Tags: gravatar |
|---|
| 3 |
copyright (c) 2004 Scott Merrill |
|---|
| 4 |
skippy@skippy.net | http://skippy.net/ |
|---|
| 5 |
|
|---|
| 6 |
This plugin is distributed with no warranty. Use it at your own risk. |
|---|
| 7 |
|
|---|
| 8 |
Please read this whole document, as new versions of the plugin will introduce new documentation. |
|---|
| 9 |
|
|---|
| 10 |
This plugin allows for the display of gravatars (Globally Recognized Avatars) throughout the blog. Each comment will display the comment owner's gravatar. If the commenter does not have a gravatar, the default gravatar (as chosen by the blog owner) will be used. Additionally, registered users can define a local gravatar that will over-ride their gravatar.com default. The blog administrator(s) can manage default gravatar settings, as well as review all local and cached gravatars. |
|---|
| 11 |
|
|---|
| 12 |
== Installation == |
|---|
| 13 |
|
|---|
| 14 |
===PART ZERO=== |
|---|
| 15 |
If you are using WordPress 1.5.1.1 or above, skip this section. |
|---|
| 16 |
|
|---|
| 17 |
If you are using WordPress 1.5 and have not yet fixed bug #902, please visit |
|---|
| 18 |
http://mosquito.wordpress.org/view.php?id=902 |
|---|
| 19 |
and apply the patch. If you don't know how to apply the patch, then do this: |
|---|
| 20 |
* edit wp-admin/menu-header.php |
|---|
| 21 |
* around line 40, you'll see the following: |
|---|
| 22 |
$page_hook = get_plugin_page_hook($item[2], $parent_file); |
|---|
| 23 |
if ( $page_hook ) |
|---|
| 24 |
* change that to read: |
|---|
| 25 |
$menu_hook = get_plugin_page_hook($item[2], $parent_file); |
|---|
| 26 |
if ( $menu_hook ) |
|---|
| 27 |
* save the file |
|---|
| 28 |
|
|---|
| 29 |
===PART ONE=== |
|---|
| 30 |
1. Create the /gravatars/ directory inside your /wp-content/ directory. For example: |
|---|
| 31 |
cd wp-content |
|---|
| 32 |
mkdir gravatars |
|---|
| 33 |
2. Make the /wp-content/gravatars/ directory writable for your webserver. For example: |
|---|
| 34 |
chgrp www-data gravatars |
|---|
| 35 |
chmod g+w gravatars |
|---|
| 36 |
3. Extract the files into the root of your WordPress directory. |
|---|
| 37 |
4. Activate the plugin in your admin Plugins page. |
|---|
| 38 |
5. Click the "Options" admin menu link, and select "Gravatars". |
|---|
| 39 |
5. Set options to your taste -- especially the default gravatar image. |
|---|
| 40 |
7. Click the "Users" admin menu link, and select "Gravatars". |
|---|
| 41 |
8. Define a local gravatar for your user account, if you so desire. |
|---|
| 42 |
|
|---|
| 43 |
===PART TWO=== |
|---|
| 44 |
Add styles for gravatars in your template's style.css. You'll need a .gravatar class for use in comments, and a .postgrav for use in posts. The following are EXAMPLE classes. You will probably need to edit these to suit your layout. |
|---|
| 45 |
|
|---|
| 46 |
.gravatar { |
|---|
| 47 |
float:left; |
|---|
| 48 |
padding: 3px; |
|---|
| 49 |
border: 1px solid #000; |
|---|
| 50 |
background: #fff; |
|---|
| 51 |
} |
|---|
| 52 |
|
|---|
| 53 |
.postgrav { |
|---|
| 54 |
float: left; |
|---|
| 55 |
padding: 3px; |
|---|
| 56 |
margin-right: 5px; |
|---|
| 57 |
margin-left: 5px; |
|---|
| 58 |
border: 1px solid #000; |
|---|
| 59 |
background: #fff; |
|---|
| 60 |
} |
|---|
| 61 |
|
|---|
| 62 |
===PART THREE=== |
|---|
| 63 |
Modify your template's comments.php file to call the gravatar() function: |
|---|
| 64 |
|
|---|
| 65 |
... |
|---|
| 66 |
<?php foreach ($comments as $comment) : |
|---|
| 67 |
if (function_exists('gravatar')) { |
|---|
| 68 |
if ('' != get_comment_author_url()) { |
|---|
| 69 |
echo "<a href='$comment->comment_author_url' title='Visit $comment->comment_author'>"; |
|---|
| 70 |
} else { |
|---|
| 71 |
echo "<a href='http://www.gravatar.com' title='Create your own gravatar at gravatar.com!'>"; |
|---|
| 72 |
} |
|---|
| 73 |
echo "<img src='"; |
|---|
| 74 |
if ('' == $comment->comment_type) { |
|---|
| 75 |
echo gravatar($comment->comment_author_email); |
|---|
| 76 |
} elseif ( ('trackback' == $comment->comment_type) || ('pingback' == $comment->comment_type) ) { |
|---|
| 77 |
echo gravatar($comment->comment_author_url); |
|---|
| 78 |
} |
|---|
| 79 |
echo "' alt='a gravatar' class='gravatar' /></a>"; |
|---|
| 80 |
} |
|---|
| 81 |
?> |
|---|
| 82 |
<div id="commentbox"> |
|---|
| 83 |
... |
|---|
| 84 |
|
|---|
| 85 |
If, after modifying your template, your blog stops outputting unexpectedly or simply presents you with a totally blank page, please check your webserver's error log. If you see the following: |
|---|
| 86 |
Parse error: parse error, unexpected T_ELSE in ... |
|---|
| 87 |
then chances are that you missed a curly brace somewhere. Double check your template. If you still have trouble, try making one small change at a time. |
|---|
| 88 |
|
|---|
| 89 |
== Advanced == |
|---|
| 90 |
===Gravatars in Posts=== |
|---|
| 91 |
You can enable (or disable) gravatars in the body of your posts. If activated, simply include in your post a line like the following: |
|---|
| 92 |
|
|---|
| 93 |
<gravatar skippy@skippy.net /> |
|---|
| 94 |
|
|---|
| 95 |
When the post is displayed to a reader, my gravatar will be included at that spot. This is a great way to personalize your <blockquoute>s. |
|---|
| 96 |
|
|---|
| 97 |
You can specify who's gravatar to use with either an email address or a URI of the form "http://www.example.com/" (you _must_ include the http:// if you're using a URI!). The gravatar() function will determine if you've supplied an email or an URI. If you supply an URI, the function will determine whether any of your commenters have used that URI, and if so the associated email address will be used to display the gravatar image. |
|---|
| 98 |
|
|---|
| 99 |
===Random Gravatars=== |
|---|
| 100 |
Version 2.3 introduces support for random default gravatars. If a commenter does not have a gravatar defined, this plugin can randomly select a gravatar image from a directory you specify. |
|---|
| 101 |
|
|---|
| 102 |
In your Options -> Gravatars administration panel, simply enter for the default gravatar a path inside your WordPress installation somewhere. |
|---|
| 103 |
|
|---|
| 104 |
** IMPORTANT ** |
|---|
| 105 |
The path you enter _must_ begin and end with a slash (/). |
|---|
| 106 |
** IMPORTANT ** |
|---|
| 107 |
|
|---|
| 108 |
** IMPORTANT ** |
|---|
| 109 |
No verification is performed on the contents of the specified directories. |
|---|
| 110 |
It is your responsibility to make sure that only valid image files are |
|---|
| 111 |
contained in this directory. |
|---|
| 112 |
** IMPORTANT ** |
|---|
| 113 |
|
|---|
| 114 |
For example, you could create the directory /wp-content/gravatars/random/ and store your collection of random gravatars in there. In the default gravatar option, you would enter |
|---|
| 115 |
/wp-content/gravatars/random/ |
|---|
| 116 |
|
|---|
| 117 |
Or you could create the directory /wp-content/random_gravatars/ and use the following value for default gravatar: |
|---|
| 118 |
/wp-content/random_gravatars/ |
|---|
| 119 |
|
|---|
| 120 |
=== Gravatar Functions === |
|---|
| 121 |
In keeping with the WordPress template tag standard, this plugin provides several tags which you can use in your templates. |
|---|
| 122 |
|
|---|
| 123 |
* wp_gravatar($who, $default) |
|---|
| 124 |
This function returns a valid URI for the gravatar of the specified email address. If local gravatar caching is disabled, this will return the default gravatar as defined in Options -> Gravatars. If no local gravatar is cached, this will return the default gravatar. |
|---|
| 125 |
$who is the email address to use for the gravatar. |
|---|
| 126 |
$default is an optional parameter. If not specified, the default gravatar image as defined in the administration settings will be used. If $default is supplied and is not blank, it will be used the default gravatar image instead. This should be a valid full URL (http://example.com/images/gravatar.png) or a valid relative path inside your webspace (/wp-content/gravatars/some_special_gravatar.png). The primary purpose of the $default parameter is to allow a different gravatar to be displayed for comments, pingbacks and trackbacks. If you find another novel use for this, please share! |
|---|
| 127 |
|
|---|
| 128 |
* gravatar($who, $default) |
|---|
| 129 |
This function merely calls wp_gravatar() and displays the results. It is this tag that you will usually use in your template files. |
|---|
| 130 |
|
|---|
| 131 |
* wp_gravatar_info($md5 = '') |
|---|
| 132 |
Given an md5 sum of an email address, this function will query gravatars.com for some information about the gravatar assigned to that email address. The information returned includes a status code, the rating of the gravatar, and a link to the gravatar.com record of the image. |
|---|
| 133 |
|
|---|
| 134 |
* random_gravatar() |
|---|
| 135 |
This function, which accepts no parameters, will return a randomly selected gravatar from the directory specified in 'default gravatar' in Options -> Gravatars. |
|---|
| 136 |
|
|---|
| 137 |
* gravatar_query($md5 = '', $default = '') |
|---|
| 138 |
This function returns the URL to gravatars.com for the specified md5 sum of an email address. It accepts an optional $default parameter which can be used to return a different default gravatar than the one defined in Options -> Gravatars. |
|---|
| 139 |
|
|---|
| 140 |
* gravatar_cache($md5 = '') |
|---|
| 141 |
This function attempts to contact gravatars.com to retreive a copy of the gravatar associated with the md5 sum of an email address. If an existing gravatar image exists, and the copy from gravatars.com is successful, the existing image will be replaced by the downloaded image. If the download fails, nothing happens to the original (if any). This function returns true or false depending on whether it was successful. |
|---|
| 142 |
|
|---|
| 143 |
===WP-Cron=== |
|---|
| 144 |
The default caching mechanism is unchanged for this version of gravatars; but the plugin now evaluates whether or not you have activated an extension for my WP-Cron plugin. If you have WP-Cron and my WP-Cron-Gravcache plugins installed and activated, no caching will occur during the normal operation of the gravatars plugin. Instead, all cache evaluation and refresh will occur once per day through use of WP-Cron. Note that individual cached gravatars still retain their own cache expiration times, which WP-Cron-Gravcache will honor. So instead of gravatar cache expiration being evaluated for every gravatar with every page view, each gravatars cache expiration will be evaluated only once per day, and updated as needed. |
|---|
| 145 |
This should help ease the burden on servers, and hopefully speed things up a bit. |
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
== UPGRADING == |
|---|
| 149 |
If you used a version of this plugin prior to 1.5, please be advised that the way the options are stored in the database has changed. Previous versions used a seperate database entry for each item on the gravatar option screen. Version 1.5 (and greater) now stores all the gravatar options as a single database row. You can safely leave the old options in the database. You're also welcome to remove the old options, if you know how. If you don't know how, you probably ought not fool around with them. |
|---|
| 150 |
|
|---|
| 151 |
Version 1.5 also introduces a new cache checking process. Each cached gravatar has a timestamp stored in the database -- the theory is that checking a value in the database is a less "expensive" process than hitting the disk's filesystem for every page view. This should drastically improve performance. Over time you'll (potentially) have lots and lots of "gravatar_expire_<email>" rows in your database. This ought not be a problem, as these options are _not_ loaded automatically -- they're only checked when the associated gravatar image is being requested. |
|---|
| 152 |
|
|---|
| 153 |
== TRANSLATING == |
|---|
| 154 |
Included in /wp-content/gravatars/ are the files necessary to translate the admin-portions of this plugin. Create a .po file for your language, and copy it to /wp-content/plugins/. |
|---|