bbp_add_user_subscription( int $user_id,  $object_id )

Add a topic to user’s subscriptions

Description

Parameters

$user_id

(Optional) User id

$topic_id

(Optional) Topic id

Return

(bool) Always true

Source

File: bp-forums/users/functions.php

function bbp_add_user_subscription( $user_id = 0, $object_id = 0 ) {
	if ( empty( $user_id ) || empty( $object_id ) ) {
		return false;
	}

	// Get the post type
	$post_type = get_post_type( $object_id );
	if ( empty( $post_type ) ) {
		return false;
	}

	switch( $post_type ) {

		// Forum
		case bbp_get_forum_post_type() :
			bbp_add_user_forum_subscription( $user_id, $object_id );
			break;

		// Topic
		case bbp_get_topic_post_type() :
		default :
			bbp_add_user_topic_subscription( $user_id, $object_id );
			break;
	}

	do_action( 'bbp_add_user_subscription', $user_id, $object_id, $post_type );

	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.