簡體   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