简体   繁体   English

无法获得buddypress用户头像网址

[英]unable to obtain buddypress user avatar url

I am working on a plugin , inside the plugin , I have made a Javascript file which I want to have a the specific user buddypress avatar url assigned to a vairable. 我正在插件,在插件中,我已经制作了一个Javascript文件,我想让一个特定的用户buddypress头像url分配给一个可用的。

My javascript file inside the plugin folder is named : myscript.js.php (so PHP can be executed inside this file). 我在插件文件夹中的javascript文件名为:myscript.js.php(因此PHP可以在此文件中执行)。

The code inside the javascript file: javascript文件中的代码:

<?php

   header('Content-type: text/javascript');

   $home_dir = preg_replace('^wp-content/plugins/[a-z0-9\-/]+^', '', getcwd());
   include($home_dir . 'wp-load.php');

$ucurrentid = $current_user->ID;
$member_id = bp_core_get_userid( $ucurrentid );
$uphoto = bp_core_fetch_avatar ( array( 'item_id' => $member_id,'html'=>false ) );

?>

var uid = <?php echo $current_user->ID ?>;
var uphoto = <?php echo $uphoto ?>;

alert(uphoto);

This return the error : PHP Fatal error: Call to undefined function bp_user_avatar() 这会返回错误:PHP致命错误:调用未定义的函数bp_user_avatar()

Why is the function undefined , which buddypress file should I include into the code so the function works? 为什么函数未定义,我应该在代码中包含哪个zeypress文件,以便该函数有效?

You can try : 你可以试试 :

$avatar_link = bp_core_fetch_avatar(array('html' =>  false, 'item_id' =>  $user_id));
$avatar = '<img title="admin" src="' . $avatar_link . '"></img>';

// Display image
echo $avatar

You need user ID. 您需要用户ID。 Inside loop, you can do : 在内部循环中,您可以:

$user_id = bp_get_member_user_id();

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

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