Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: New Users Auto Subscribe to One Forum

@nhadsall

Participant

So, after DAYS of working on this I finally have a solution. I have not done a lot of testing, but this has worked so far.

Basically what is happening is that for forums (not replies) the logic is inverted. This means that users are subscribed to a forum unless they unsubscribe (ie. are added to the DB).

Just add this to your theme’s function.php and it should work.

I hope this helps someone, because it has taken a LOT of work!

add_filter( 'bbp_get_user_subscribe_link', 'invert_get_user_subscribe_link', 10, 4 ); //invert forum subscription
add_filter( 'bbp_is_user_subscribed_to_forum', 'invert_is_user_subscribed_to_forum', 10, 4 ); //invert forum subscription
add_filter( 'bbp_get_forum_subscribers', 'invert_get_forum_subscribers' ); //invert forum subscription
add_filter( 'bbp_is_user_subscribed', 'invert_is_user_subscribed', 10, 4 ); //invert forum subscription

function invert_is_user_subscribed($retval, $user_id, $object_id, $subscribed_ids) {
	if (get_post_type( $object_id ) == bbp_get_forum_post_type())
		return !$retval;
	else	
		return $retval;
}

function strContains($needle, $haystack) {
	if (strpos($haystack, $needle) !== false) {
		return true;
	} else {
		return false;
	}
}

function invert_get_user_subscribe_link ($html, $r, $user_id, $topic_id) {
	if (strContains( "bbp_unsubscribe", $html )) {
		$html = str_replace("bbp_unsubscribe", "bbp_subscribe", $html);
	} else {
		$html = str_replace("bbp_subscribe", "bbp_unsubscribe", $html);
	}
	return $html;
}

function invert_get_forum_subscribers( $users ) {
	$args = array('fields' => 'id');
	$all_users = get_users($args);
	$send_to_users    = array_diff($all_users, $users);
	return $send_to_users;
}

function invert_is_user_subscribed_to_forum( $retval, $user_id, $forum_id, $subscribed_ids ) {
	return !$retval;
}

I also include make users “subscribed” to anything they write by default. All they have to do is uncheck the box. The following code is also added to function.php.

add_action('bbp_theme_after_topic_form_subscriptions', 'subscribed_by_default'); //default subscribe
add_action('bbp_theme_after_reply_form_subscription', 'subscribed_by_default'); //default subscribe

function subscribed_by_default() 
	echo '<script type="text/javascript">jQuery("#bbp_topic_subscription").prop("checked","checked");</script>';
}
Skip to toolbar