我正在一個插件裏面的插件,我已經做了一個Javascript文件,我想有一個可分辨的具體用戶buddypress頭像網址。無法獲得buddypress用戶頭像url
我的JavaScript文件內的插件文件夾名爲:myscript.js.php(所以PHP可以在這個文件中執行)。
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);
這將返回錯誤: PHP致命錯誤:調用未定義功能bp_user_avatar()
爲什麼是函數定義,這BuddyPress的文件,我應該包含在代碼中,這樣的功能工作?