Gravatars2. Author: Peter Sterling Author URI: http://www.sterling-adventures.co.uk Version: 2.0 Change: 1.0 - Initial release. 2.0 - Added options menu for easier 'non-technical user' control. */ // Local avatar cache. $pws_local_avatars; // Default options. $pws_avatar_options = bb_get_option('plugin_pws_avatars'); if(!is_array($pws_avatar_options)) { // Options do not exist or have not yet been loaded so we define standard options... $pws_avatar_options = array( 'local_folder' => '', 'default_avatar_uri' => 'http://', 'avatar_size' => '30', 'use_snap_shots' => 'on' ); } // Cache local avatars if needed and return if found. function pws_get_local_avatar($email) { global $pws_local_avatars; // If not already cached get the local avatar array from the WordPress database. if(empty($pws_local_avatars)) { global $bbdb, $bb; $res = $bbdb->get_row("select option_value from {$bb->wp_table_prefix}options where option_name = 'gravatar_local' limit 1"); $pws_local_avatars = unserialize($res->option_value); } // Return the avatar indexed by the supplied email address. return $pws_local_avatars[$email]; } // Display an avatar. function pws_get_avatar() { global $pws_avatar_options; // Get the post author's email address. $post_author_email = bb_get_user_email(get_post_author_id()); // See if there is a local avatar for that email address. $local = pws_get_local_avatar($post_author_email); // Decide if the avatar output is local or gravatar supplied. if(!empty($local)) $src = $pws_avatar_options['local_folder'] . $local; else { $md5 = md5($post_author_email); $default = urlencode($pws_avatar_options['default_avatar_uri']); $src = "http://www.gravatar.com/avatar.php?gravatar_id=$md5&size=" . $pws_avatar_options['avatar_size'] . "&default=$default"; } // Output the avatar, wrapping it in an author link if there is one. $link = get_user_link(get_post_author_id()); if($link) echo '' : 'class="snap_noshots">'); echo ""; if($link) echo ''; } // Output HTML for plug-in options page. function pws_options_page() { global $pws_avatar_options; ?>

Avatar Options

Control the bevaiour of the avatar plug-in.
This plug-in gets an avatar from gravatar.com, or uses a local avatar cached by the WordPress plugin Gravatars2.

Please visit the author's site, Sterling Adventures, and say "Hi"...

Avatar Plug-in Settings
Path to local avatar folder
You may use a complete or relative path. For example,
../wordpress/wp-content/gravatars/local/
Default avatar URI
You should use a complete URI. For example,
http://www.your-site.com/wordpress/wp-content/gravatars/default.jpg
Size of avatar image
/> Use snap shots?

Avatar Plug-in Usage After activating the plug-in...
  1. Set the options above.
  2. Place this PHP code in your theme's template files where you want the user avatars to appear.
    Note: An example posts.php is included with the plug-in download.

    <?php if(function_exists('pws_get_avatar')) pws_get_avatar(); ?>

$_POST['local_folder'], 'default_avatar_uri' => $_POST['default_avatar_uri'], 'avatar_size' => $_POST['avatar_size'], 'use_snap_shots' => $_POST['use_snap_shots'] ); bb_update_option('plugin_pws_avatars', $pws_avatar_options_update); $pws_avatar_options = bb_get_option('plugin_pws_avatars'); } } } // Menu hooks... add_action('bb_admin_menu_generator', 'pws_options_menu'); add_action('bb_admin-header.php', 'pws_page_process'); ?>