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.
My javascript file inside the plugin folder is named : myscript.js.php (so PHP can be executed inside this file).
The code inside the javascript file:
<?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()
Why is the function undefined , which buddypress file should I include into the code so the function works?
This works for me:
http://viviendoenlaeradelaweb20.blogspot.com/2013/03/buddypress-avatar-url.html
I hope will be useful :-)
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. Inside loop, you can do :
$user_id = bp_get_member_user_id();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.