bbp_get_favorites_permalink( int $user_id )
Return the link to the user’s favorites page (profile page)
Description
Parameters
- $user_id
-
(Optional) User id
Return
(string) Permanent link to user profile page
Source
File: bp-forums/users/template.php
function bbp_get_favorites_permalink( $user_id = 0 ) {
global $wp_rewrite;
// Use displayed user ID if there is one, and one isn't requested
$user_id = bbp_get_user_id( $user_id );
if ( empty( $user_id ) )
return false;
// Allow early overriding of the profile URL to cut down on processing
$early_profile_url = apply_filters( 'bbp_pre_get_favorites_permalink', (int) $user_id );
if ( is_string( $early_profile_url ) )
return $early_profile_url;
// Pretty permalinks
if ( $wp_rewrite->using_permalinks() ) {
$url = $wp_rewrite->root . bbp_get_user_slug() . '/%' . bbp_get_user_rewrite_id() . '%/%' . bbp_get_user_favorites_rewrite_id() . '%';
$user = get_userdata( $user_id );
if ( ! empty( $user->user_nicename ) ) {
$user_nicename = $user->user_nicename;
} else {
$user_nicename = $user->user_login;
}
$url = str_replace( '%' . bbp_get_user_rewrite_id() . '%', $user_nicename, $url );
$url = str_replace( '%' . bbp_get_user_favorites_rewrite_id() . '%', bbp_get_user_favorites_slug(), $url );
$url = home_url( user_trailingslashit( $url ) );
// Unpretty permalinks
} else {
$url = add_query_arg( array(
bbp_get_user_rewrite_id() => $user_id,
bbp_get_user_favorites_rewrite_id() => bbp_get_user_favorites_slug(),
), home_url( '/' ) );
}
return apply_filters( 'bbp_get_favorites_permalink', $url, $user_id );
}
Changelog
| Version | Description |
|---|---|
| bbPress (r2652) | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.