brasofilo

Gravatars : Add, Reorder and change Default

Oct 22nd, 2011
139
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3.     Inspired by this thread:
  4.                   www.wptavern.com/forum/themes-templates/1756-default-avatar-filter-hooks.html
  5.     Author: brasofilo
  6.     Description: adds two gravatars to the list, marks the first one as default, deletes all WP built-in gravatars
  7.     Usage: drop in your functions.php - change $del_defaults to suit your needs
  8. */
  9.  
  10. if ( !function_exists('bsf_addgravatar') ) {
  11.     function bsf_addgravatar( $avatar_defaults ) {
  12.         $temp_avatars = $avatar_defaults;
  13.         unset($avatar_defaults);
  14.  
  15.         // files are inside your-theme/images directory
  16.         $pathavatar = get_bloginfo('template_directory');
  17.         $myavatar1 = $pathavatar . '/images/avatar1.gif';
  18.         $myavatar2 = $pathavatar . '/images/avatar2.png';
  19.         $bavatar[$myavatar1] = 'New Avatar';
  20.         $bavatar[$myavatar2] = 'Brand New Bravatar';
  21.  
  22.         $del_defaults = true; // Your option...
  23.            
  24.         if($del_defaults) $avatar_defaults = $bavatar;
  25.         else $avatar_defaults = array_merge((array)$bavatar, (array)$temp_avatars);
  26.  
  27.         // best way i found to get rid of the 'mystery' default    
  28.         $default = get_option('avatar_default');
  29.         if ( empty($default) || $default=='mystery' ) update_option( 'avatar_default', $myavatar1);
  30.  
  31.         return $avatar_defaults;
  32.     }
  33.     add_filter( 'avatar_defaults', 'bsf_addgravatar' );
  34. }
RAW Paste Data