我试图做一个功能,覆盖当前用户头像的URL与保存在他们的用户元的自定义URL。到目前为止,功能工程,除了我难以想象如何让功能抓住用户buddypress/wordpress的用户ID获得头像。BuddyPress/Wordpress获取动态用户ID
到目前为止的代码看起来是这样的:
// return new URL for avatar
function wpse_49216_my_new_avatar_url() {
// get user_id of user bp/wp is getting avatar for
$user_id = bp_get_member_user_id();
// get avatar name from above user's meta
$avatar_choice = get_user_meta($user_id, "avatar_choice", true);
if($avatar_choice) {
return 'path_to_avatars/'.$avatar_choice.'.png';
} else {
return 'path_to_avatars/default-avatar.png';
}
}
add_filter('bp_core_fetch_avatar_url', 'wpse_49216_my_new_avatar_url');
// Replace image src="" with the new avatar URL
function wpse_49216_filter_bp_avatar($html) {
return preg_replace('/src=".+?"/', 'src="' . wpse_49216_my_new_avatar_url() . '"', $html );
}
add_filter('bp_core_fetch_avatar', 'wpse_49216_filter_bp_avatar');
主要的问题是,如果我设置$ USER_ID,以登录用户的ID的电流,那么所有的头像将加载记录在当前的化身用户。而bp_get_member_user_id()
只适用于会员页面。我需要普遍适用的东西。有没有WordPress的/ Buddypress专家有任何想法如何我可以得到正确的用户ID?