简体   繁体   English

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

[英]How come I cannot use bp_core_fetch_avatar() in the theme after I add filter in the plugin, wordpress buddypress?

After I do the add_filter code below in the first plugin, I cannot use bp_core_fetch_avatar() in the second plugin or in the theme, it echo out the same avatar for every user, why? 在第一个插件中执行以下add_filter代码后,无法在第二个插件或主题中使用bp_core_fetch_avatar(),它为每个用户回显相同的化身,为什么? How can I fix this? 我怎样才能解决这个问题? get_avatar can echo out different avatar base on the user except that it cannot recognize the $gender that I create in the plugin which will tell if it is a female or male, so avatar will assign base on gender . get_avatar可以根据用户回显不同的头像,只是无法识别我在插件中创建的$ gender,它将告诉它是女性还是男性,因此avatar会根据性别进行分配。 I am trying to pass some parameter like $gender that I created in the plugin, so that is why I think I should figure out to use bp_core_fetch_avatar(), by the way, does get_avatar can pass a parameter from a plugin?, I know get_avatar( $id, $size,$default, $alt). 我试图传递一些在插件中创建的参数,例如$ gender,所以这就是为什么我认为我应该弄清楚使用bp_core_fetch_avatar()的原因,get_avatar可以从插件传递参数吗?我知道get_avatar($ id,$ size,$ default,$ alt)。 Anyway, I want to know why bp_core_fetch_avatar() echo out same avatar for every user after do the add_filter, I already add 'item_id'=>"$id". 无论如何,我想知道为什么bp_core_fetch_avatar()在执行add_filter之后为每个用户回显相同的化身,我已经添加了'item_id'=>“ $ id”。 Thanks 谢谢

  <?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; } } ?> 

I want to know why bp_core_fetch_avatar() echo out same avatar for every user after do the add_filter 我想知道为什么bp_core_fetch_avatar()在执行add_filter之后为每个用户回显相同的头像

Because you added a filter to a core BP function. 因为您核心BP函数添加了过滤器 Try removing the filter after you are finished with it in your class. 在课堂上完成过滤器后,请尝试将其删除。

remove_filter#Example remove_filter#实施例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM