2013-09-23 41 views
0

我试图做一个功能,覆盖当前用户头像的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?

回答

0

我需要的东西,如果你看一下你过滤功能的作品普遍

,你会看到,它依赖于知道“其中”你是在BP。由于它是由背景驱动的,因此没有通用的方法。

0

您可以在下面的用户为泛函全球用户ID:

bp_displayed_user_id()