繁体   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?

在第一个插件中执行以下add_filter代码后,无法在第二个插件或主题中使用bp_core_fetch_avatar(),它为每个用户回显相同的化身,为什么? 我怎样才能解决这个问题? get_avatar可以根据用户回显不同的头像,只是无法识别我在插件中创建的$ gender,它将告诉它是女性还是男性,因此avatar会根据性别进行分配。 我试图传递一些在插件中创建的参数,例如$ gender,所以这就是为什么我认为我应该弄清楚使用bp_core_fetch_avatar()的原因,get_avatar可以从插件传递参数吗?我知道get_avatar($ id,$ size,$ default,$ alt)。 无论如何,我想知道为什么bp_core_fetch_avatar()在执行add_filter之后为每个用户回显相同的化身,我已经添加了'item_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; } } ?> 

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

因为您核心BP函数添加了过滤器 在课堂上完成过滤器后,请尝试将其删除。

remove_filter#实施例

暂无
暂无

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

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