bbp_add_user_favorite( int $user_id, int $topic_id )
Add a topic to user’s favorites
Description
Parameters
- $user_id
-
(Optional) User id
- $topic_id
-
(Optional) Topic id
Return
(bool) Always true
Source
File: bp-forums/users/functions.php
function bbp_add_user_favorite( $user_id = 0, $topic_id = 0 ) { if ( empty( $user_id ) || empty( $topic_id ) ) return false; $topic = bbp_get_topic( $topic_id ); if ( empty( $topic ) ) return false; $favorites = bbp_get_user_favorites_topic_ids( $user_id ); if ( !in_array( $topic_id, $favorites ) ) { $favorites[] = $topic_id; $favorites = implode( ',', wp_parse_id_list( array_filter( $favorites ) ) ); update_user_option( $user_id, '_bbp_favorites', $favorites ); } do_action( 'bbp_add_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.