bbp_remove_user_favorite( int $user_id, int $topic_id )
Remove a topic from user’s favorites
Description
Parameters
- $user_id
-
(Optional) User id
- $topic_id
-
(Optional) Topic id
Return
(bool) True if the topic was removed from user's favorites, otherwise false
Source
File: bp-forums/users/functions.php
function bbp_remove_user_favorite( $user_id, $topic_id ) {
if ( empty( $user_id ) || empty( $topic_id ) )
return false;
$favorites = (array) bbp_get_user_favorites_topic_ids( $user_id );
if ( empty( $favorites ) )
return false;
$pos = array_search( $topic_id, $favorites );
if ( is_numeric( $pos ) ) {
array_splice( $favorites, $pos, 1 );
$favorites = array_filter( $favorites );
if ( !empty( $favorites ) ) {
$favorites = implode( ',', wp_parse_id_list( $favorites ) );
update_user_option( $user_id, '_bbp_favorites', $favorites );
} else {
delete_user_option( $user_id, '_bbp_favorites' );
}
}
do_action( 'bbp_remove_user_favorite', $user_id, $topic_id );
return true;
}
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.