Skip to:
Content

bbPress.org

Opened 5 years ago

Last modified 2 months ago

#3360 new defect (bug)

Conflict in bbp_unsubscribe action with Buddypress

Reported by: sirlouen's profile SirLouen Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: trunk
Component: API - Subscriptions Keywords: has-patch
Cc: tanner, m

Description

By default, bbp_unsubscribe action works fine both AJAX and link versions

For example:
The subscribe button on top of a forum is an AJAX version
The unsubscribe button in the "subscription" section within a user profile is a link version

By installing Buddypress the AJAX version works fine, but the link version breaks

This can be tested after installing Buddypress by subscribing to a forum and trying to unsubscribe by using the current nonce and the forum ID using the full URL with the adequate parameters (or just by going to the ->members->forums->subscription and trying to unsubscribe by pressing the button.

?action=bbp_unsubscribe&object_id=xxx&object_type=post&_wpnonce=xxxxxxxx

Attachments (1)

bbp-buddypress-subscription-fix.patch (581 bytes) - added by tanner m 2 months ago.

Download all attachments as: .zip

Change History (2)

#1 @tanner m
2 months ago

  • Cc tanner m added
  • Keywords has-patch added; needs-patch removed

I've identified the issue and created a patch that fixes the problem.

Issue Description

The subscription system in bbPress has two ways of handling unsubscribe actions:

  1. AJAX-based subscribe / unsubscribe (works with BuddyPress, per the original issue description)
  2. Link-based subscribe / unsubscribe (breaks with BuddyPress)

The problem occurs because BuddyPress passes the action parameter differently than standard bbPress. In the bbp_subscriptions_handler() function, BuddyPress doesn't pass any parameters via the bp_actions hook - so we need to look it up in the $_GET parameter. When a user clicks the subscribe / unsubscribe link in their profile, the function receives an empty $action parameter and cannot determine what action to take.

Solution

The fix is simple: we check for the action in $_GET when the function's $action parameter is empty. This maintains compatibility with the standard bbPress implementation while also supporting BuddyPress's implementation.

// BuddyPress doesn't send the $action parameter, so we need to check for it
if ( empty( $action ) && isset( $_GET['action'] ) && is_string( $_GET['action'] ) ) {
    $action = sanitize_key( $_GET['action'] );
}

Testing

I've verified this fix works by:

  1. Setting up a test environment with BuddyPress installed
  2. Verifying the subscribe / unsubscribe link in user profiles now works correctly with this patch

I've attached the patch file for review. This is a minimal change with no side effects to standard bbPress functionality.

Note: See TracTickets for help on using tickets.