bbp_is_user_subscribed_to_topic( int $user_id, int $topic_id, array $subscribed_ids = array() )

Check if a topic is in user’s subscription list or not

Description

Parameters

$user_id

(Optional) User id

$topic_id

(Optional) Topic id

$subscribed_ids

(Optional) Array of topic ID's to check

Default value: array()

Return

(bool) True if the topic is in user's subscriptions, otherwise false

Source

File: bp-forums/users/functions.php

810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
function bbp_is_user_subscribed_to_topic( $user_id = 0, $topic_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_topic_ids( $user_id );
        }
 
        // User has topic subscriptions
        if ( ! empty( $subscribed_ids ) ) {
 
            // Checking a specific topic id
            if ( ! empty( $topic_id ) ) {
                $topic    = bbp_get_topic( $topic_id );
                $topic_id = ! empty( $topic ) ? $topic->ID : 0;
 
            // Using the global topic id
            } elseif ( bbp_get_topic_id() ) {
                $topic_id = bbp_get_topic_id();
 
            // Use the current post id
            } elseif ( !bbp_get_topic_id() ) {
                $topic_id = get_the_ID();
            }
 
            // Is topic_id in the user's favorites
            if ( ! empty( $topic_id ) ) {
                $retval = in_array( $topic_id, $subscribed_ids );
            }
        }
    }
 
    return (bool) apply_filters( 'bbp_is_user_subscribed_to_topic', (bool) $retval, $user_id, $topic_id, $subscribed_ids );
}

Changelog

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.