bbp_remove_user_topic_subscription( int $user_id, int $topic_id )

Remove a topic from user’s subscriptions

Description

Parameters

$user_id

(Optional) User id

$topic_id

(Optional) Topic id

Return

(bool) True if the topic was removed from user's subscriptions, otherwise false

Source

File: bp-forums/users/functions.php

1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
function bbp_remove_user_topic_subscription( $user_id, $topic_id ) {
    if ( empty( $user_id ) || empty( $topic_id ) ) {
        return false;
    }
 
    $subscriptions = (array) bbp_get_user_subscribed_topic_ids( $user_id );
    if ( empty( $subscriptions ) ) {
        return false;
    }
 
    $pos = array_search( $topic_id, $subscriptions );
    if ( false === $pos ) {
        return false;
    }
 
    array_splice( $subscriptions, $pos, 1 );
    $subscriptions = array_filter( $subscriptions );
 
    if ( !empty( $subscriptions ) ) {
        $subscriptions = implode( ',', wp_parse_id_list( $subscriptions ) );
        update_user_option( $user_id, '_bbp_subscriptions', $subscriptions );
    } else {
        delete_user_option( $user_id, '_bbp_subscriptions' );
    }
 
    wp_cache_delete( 'bbp_get_topic_subscribers_' . $topic_id, 'bbpress_users' );
 
    do_action( 'bbp_remove_user_topic_subscription', $user_id, $topic_id );
 
    return true;
}

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.