当我在第一个插件中完成下面的add_filter代码后,我不能在第二个插件或主题中使用bp_core_fetch_avatar(),它为每个用户回显相同的头像,为什么?我该如何解决这个问题呢?get_avatar可以根据用户回显不同的头像,除了它不能识别我在插件中创建的$gender,它会告诉你它是女性还是男性,所以头像将根据性别进行分配。我正在尝试传递一些参数,比如我在插件中创建的$gender,所以这就是为什么我认为我应该使用bp_core_fetch_avatar(),顺便问一下,get_avatar可以传递来自插件的参数吗?,我知道get_avatar( $id,$size,$default,$alt)。不管怎样,我想知道为什么bp_core_fetch_avatar()在做完项目之后会为每个用户返回相同的头像,我已经添加了‘add_filter _id’=>“$id”。谢谢
<?php
add_filter('bp_core_fetch_avatar',array($this,'set_buddypress_avatar'), 10, 1);
?>
<?php
public function set_buddypress_avatar($html_data = ''){
$html_doc = new DOMDocument();
$html_doc->loadHTML($html_data);
$image = $html_doc->getElementsByTagName('img');
foreach($image as $data) {
$original_image = $data->getAttribute('src');
$size = $data->getAttribute('width');
$alt = $data->getAttribute('alt');
if (stripos($alt, 'Profile picture of ') === 0){ // if our alt attribute has "profile picture of" in the beginning...
$name = str_replace('Profile picture of ', '', $alt);
} else if (stripos($alt, 'Profile photo of ') === 0){ // or profile photo of...
$name = str_replace('Profile photo of ', '', $alt);
} else { // if there is some problem - just assign alt to name
$name = $alt;
}
}
?>
发布于 2015-03-17 11:59:19
我想知道为什么在执行add_filter之后,bp_core_fetch_avatar()会为每个用户返回相同的头像
因为您向核心BP函数添加了一个过滤器。在类中使用完过滤器后,请尝试将其移除。
https://stackoverflow.com/questions/29087474
复制相似问题