社区首页 >问答首页 >为什么在插件wordpress buddypress中添加过滤器后,我不能在主题中使用bp_core_fetch_avatar()?

为什么在插件wordpress buddypress中添加过滤器后,我不能在主题中使用bp_core_fetch_avatar()?
EN

Stack Overflow用户
提问于 2015-03-16 21:42:12
回答 1查看 309关注 0票数 1

当我在第一个插件中完成下面的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”。谢谢

代码语言:javascript
代码运行次数:0
复制
           <?php
          add_filter('bp_core_fetch_avatar',array($this,'set_buddypress_avatar'), 10, 1);

       ?>
代码语言:javascript
代码运行次数:0
复制
<?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;
			    
			}
		}

?>

EN

回答 1

Stack Overflow用户

发布于 2015-03-17 11:59:19

我想知道为什么在执行add_filter之后,bp_core_fetch_avatar()会为每个用户返回相同的头像

因为您向核心BP函数添加了一个过滤器。在类中使用完过滤器后,请尝试将其移除。

remove_filter#Example

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29087474

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文