bbp_add_user_favorite( int $user_id, int $topic_id )
Add a topic to user’s favorites
Description Description
Note that both the User and Topic should be verified to exist before using this function. Originally both were validated, but because this function is frequently used within a loop, those verifications were moved upstream to improve performance on topics with many engaged users.
Parameters Parameters
- $user_id
-
(Optional) User id
- $topic_id
-
(Optional) Topic id
Return Return
(bool) True if the topic was added to user's favorites, otherwise false
Source Source
File: includes/users/engagements.php
function bbp_add_user_favorite( $user_id = 0, $topic_id = 0 ) { $user_id = bbp_get_user_id( $user_id, false, false ); $topic_id = bbp_get_topic_id( $topic_id ); // Bail if not enough info if ( empty( $user_id ) || empty( $topic_id ) ) { return false; } // Bail if already a favorite if ( bbp_is_user_favorite( $user_id, $topic_id ) ) { return false; } // Bail if add fails if ( ! bbp_add_user_to_object( $topic_id, $user_id, '_bbp_favorite' ) ) { return false; } do_action( 'bbp_add_user_favorite', $user_id, $topic_id ); return true; }
Changelog Changelog
Version | Description |
---|---|
2.0.0 | Introduced. |