我想为我的wp网站使用本地头像系统,我想过滤get_avatar()
它将从我的服务器返回头像,而不是默认的gavatar。
我有以下代码:
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;
}
}
并返回以下错误:
警告:在/home/subhi/public\\u html/work/example中缺少local\\u avatar::get\\u avatar()的参数2。com/wp-content/plugins/ahaali\\u-avatar/core。php在线40
警告:在/home/subhi/public\\u html/work/example中缺少local\\u avatar::get\\u avatar()的参数4。com/wp-content/plugins/ahaali\\u-avatar/core。php在线40
我如何解决这个问题?
SO网友:brasofilo
原来的海报找不到这对priority, parameters
声明筛选器挂钩时:
add_filter( \'get_avatar\', array( $this, \'get_avatar\' ), 10, 5 );
存在
5
回调函数可以使用的所有参数:
public function get_avatar( $avatar, $id_or_email, $size, $default, $alt )
{
return $avatar;
}