bbp_is_user_subscribed_to_forum( int $user_id, int $forum_id, array $subscribed_ids = array() )
Check if a forum is in user’s subscription list or not
Description
Parameters
- $user_id
-
(Optional) User id
- $forum_id
-
(Optional) Topic id
- $subscribed_ids
-
(Optional) Array of forum ID's to check
Default value: array()
Return
(bool) True if the forum is in user's subscriptions, otherwise false
Source
File: bp-forums/users/functions.php
function bbp_is_user_subscribed_to_forum( $user_id = 0, $forum_id = 0, $subscribed_ids = array() ) { // Assume user is not subscribed $retval = false; // Validate user $user_id = bbp_get_user_id( $user_id, true, true ); if ( ! empty( $user_id ) ) { // Get subscription ID's if none passed if ( empty( $subscribed_ids ) ) { $subscribed_ids = bbp_get_user_subscribed_forum_ids( $user_id ); } // User has forum subscriptions if ( ! empty( $subscribed_ids ) ) { // Checking a specific forum id if ( ! empty( $forum_id ) ) { $forum = bbp_get_forum( $forum_id ); $forum_id = ! empty( $forum ) ? $forum->ID : 0; // Using the global forum id } elseif ( bbp_get_forum_id() ) { $forum_id = bbp_get_forum_id(); // Use the current post id } elseif ( ! bbp_get_forum_id() ) { $forum_id = get_the_ID(); } // Is forum_id in the user's favorites if ( ! empty( $forum_id ) ) { $retval = in_array( $forum_id, $subscribed_ids ); } } } return (bool) apply_filters( 'bbp_is_user_subscribed_to_forum', (bool) $retval, $user_id, $forum_id, $subscribed_ids ); }
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.