我正在尝试使用过滤器 bp_core_get_user_domain 更改buddypress中的显示用户子弹 该过滤器的引用位于wp-content \ plugins \ buddypress \ bp-members \ bp-members-functions.php,沿行号172
该函数的内容是:
function bp_core_get_user_domain( $user_id = 0, $user_nicename = false, $user_login = false ) {
if ( empty( $user_id ) ) {
return;
}
$username = bp_core_get_username( $user_id, $user_nicename, $user_login );
if ( bp_is_username_compatibility_mode() ) {
$username = rawurlencode( $username );
}
$after_domain = bp_core_enable_root_profiles() ? $username : bp_get_members_root_slug() . '/' . $username;
$domain = trailingslashit( bp_get_root_domain() . '/' . $after_domain );
// Don't use this filter. Subject to removal in a future release.
// Use the 'bp_core_get_user_domain' filter instead.
$domain = apply_filters( 'bp_core_get_user_domain_pre_cache', $domain, $user_id, $user_nicename, $user_login );
/**
* Filters the domain for the passed user.
*
* @since 1.0.1
*
* @param string $domain Domain for the passed user.
* @param int $user_id ID of the passed user.
* @param string $user_nicename User nicename of the passed user.
* @param string $user_login User login of the passed user.
*/
return apply_filters( 'bp_core_get_user_domain', $domain, $user_id, $user_nicename, $user_login );
}
我正在尝试像这样使用它:
function my_custom_filter($domain, $user_id) {
$oldSlug= get_user_slug_by_user_id($user_id);
if ($oldSlug==='foo') {
$domain = trailingslashit(bp_get_root_domain() . '/' . 'members/' . 'bar');
}
return $domain;
}
add_filter('bp_core_get_user_domain', 'my_custom_filter', 10, 2);
此过滤器更改为,每当访问example.com/members/foo
时,它将转到example.com/members/bar
问题
这按预期工作,但我的问题是
example.com/members/bar
是404。
如果我禁用了过滤器,但它转到example.com/members/foo
,则所有ajax都可以使用200。