I want to use local avatar system for my wp website , I want to filter the get_avatar()
function so it will return the avatar from my server instead of the default gavatar .
I have the following code :
class local_avatar{
function __construct(){
add_filter('get_avatar',array($this,'get_avatar'));
}
public function get_avatar($avatar , $id_or_email , $size = '96' , $default , $alt = false){
global $wpdb;
$upload = wp_upload_dir();
if(is_numeric($id_or_email)){
// the user id
$image = get_user_meta($id_or_email,'_ahaali_avatar',true);
if($image){
$image_path = $upload['baseurl'].'/avatar/'.$image;
$ahaali_avatar = '<img src="'.$image_path.'" width="'.$size.'" height="'.$size.'" />';
}else{
$image_path = 'http://0.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536?s='.$size;
$ahaali_avatar = '<img src="'.$image_path.'" width="'.$size.'" height="'.$size.'" />';
}
}elseif(is_string($id_or_email)){
// the user email
$user_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM wp_users WHERE user_email = %s",
$id_or_email));
$image = get_user_meta($user_id,'_ahaali_avatar',true);
if($image){
$image_path = $upload['baseurl'].'/avatar/'.$image;
$ahaali_avatar = '<img src="'.$image_path.'" width="'.$size.'" height="'.$size.'" />';
}else{
$image_path = 'http://0.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536?s='.$size;
$ahaali_avatar = '<img src="'.$image_path.'" width="'.$size.'" height="'.$size.'" />';
}
}
return $ahaali_avatar;
}
}
And it returns the following errors :
Warning: Missing argument 2 for local_avatar::get_avatar() in /home/subhi/public_html/work/example.com/wp-content/plugins/ahaali_avatar/core.php on line 40
Warning: Missing argument 4 for local_avatar::get_avatar() in /home/subhi/public_html/work/example.com/wp-content/plugins/ahaali_avatar/core.php on line 40
How can I solve this?
The Original Poster was missing the pair
priority, parameters
when declaring the filter hook:Being
5
all the parameters the callback function can use:You can easy add new avatars with this function:
In the admin area go to the Settings tabs â> Discussion and select your new avatar as default and click save.