bbp_add_user_forum_subscription( int $user_id, int $forum_id )
Add a forum to user’s subscriptions
Description
Parameters
- $user_id
-
(Optional) User id
- $forum_id
-
(Optional) forum id
Return
(bool) Always true
Source
File: bp-forums/users/functions.php
function bbp_add_user_forum_subscription( $user_id = 0, $forum_id = 0 ) { if ( empty( $user_id ) || empty( $forum_id ) ) { return false; } $forum = bbp_get_forum( $forum_id ); if ( empty( $forum ) ) { return false; } $subscriptions = (array) bbp_get_user_subscribed_forum_ids( $user_id ); if ( !in_array( $forum_id, $subscriptions ) ) { $subscriptions[] = $forum_id; $subscriptions = implode( ',', wp_parse_id_list( array_filter( $subscriptions ) ) ); update_user_option( $user_id, '_bbp_forum_subscriptions', $subscriptions ); wp_cache_delete( 'bbp_get_forum_subscribers_' . $forum_id, 'bbpress_users' ); } do_action( 'bbp_add_user_forum_subscription', $user_id, $forum_id ); return true; }
Changelog
Version | Description |
---|---|
bbPress (r5156) | 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.