Opened 3 weeks ago
Last modified 3 weeks ago
#3755 new enhancement
Subscriptions: Add a bulk topic unsubscribe action
| Reported by: | johnjamesjacoby | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | 2.7 |
| Component: | API - Subscriptions | Version: | trunk |
| Severity: | normal | Keywords: | needs-patch needs-unit-tests |
| Cc: |
Description
bbPress lets users remove subscriptions one topic at a time from their Subscriptions profile screen, but it does not provide a way to clear all topic subscriptions.
WordPress.org added an "Unsubscribe from all topics" action in 13219 for meta:#5920. That implementation:
- Displays the action only when topic subscriptions exist.
- Permits the displayed user or someone who can
edit_user. - Verifies a user-specific nonce.
- Uses
bbp_remove_user_from_all_objects( $user_id, '_bbp_subscription' ), which core already provides.
The missing core behavior is a first-class, theme-compatible form and request handler with clear destructive wording, authorization, nonce validation, and success or failure feedback.
The focused implementation should remove topic subscriptions only. Forum subscriptions should remain separate so one ambiguous action cannot unexpectedly remove both relationship types.
Tests should cover a user clearing their own subscriptions, an authorized administrator acting for another user, rejected unauthorized and invalid-nonce requests, no action when there are no subscriptions, and the resulting engagement state.
Attachments (1)
Change History (2)
#1
@
3 weeks ago
3755.01.patch adds an "Unsubscribe from all topics" form and request handler to the profile Subscriptions screen, as described in the ticket. The new bbp_remove_all_user_topic_subscriptions( $user_id ) removes the user's topic subscriptions and does not change forum subscriptions. It does not use bbp_remove_user_from_all_objects( $user_id, '_bbp_subscription' ) like the WordPress.org code for meta:#5920, because forums and topics use the same _bbp_subscription key, so with the meta strategy (the default) and the term strategy it removes the forum subscriptions too.
Testing Instructions
These steps define how to test the feature or enhancement, and indicates the expected behavior or results.
Environment
- OS: Debian GNU/Linux 13 (wordpress-develop Docker environment, on Windows 11)
- Web Server: nginx 1.31.3
- Database: MySQL 9.7.1
- PHP: 8.3.32
- WordPress: 7.2-beta1-64606-src
- Browser: n/a (PHPUnit test)
- Theme: default (PHPUnit test suite)
- Active Plugins:
- bbPress trunk (r8132, git f1acdfef) with 3755.01.patch
Steps to Test
- Log in as a user who is subscribed to some topics and to a forum, and open your profile's Subscriptions page.
- Click "Unsubscribe from all topics" and confirm.
- Log in as an administrator, open another user's Subscriptions page and do the same.
- Send the same request with an invalid nonce, with a nonce made for another user, as a participant with a valid nonce of their own on another user's profile, and as a logged out visitor.
- Open the Subscriptions page of a user who has only a forum subscription, then send the request for that user.
Expected Results
Lists each expected result or behavior, i.e. what should happen when running the test(s):
- ✅ Step 2: your topic subscriptions are removed. You are sent back to the Subscriptions page with
topic-subscriptions=removed, and the notice "All topic subscriptions were removed. Forum subscriptions were not changed." is shown. - ✅ Step 3: the other user's topic subscriptions are removed, and the administrator's own subscriptions stay.
- ✅ Step 4: each request is rejected with an error notice, and the subscriptions stay.
- ✅ Step 5: the form is not shown. The request removes nothing, the forum subscription stays, and the
bbp_remove_user_subscriptionaction does not run. - ✅ Forum subscriptions are kept with the meta, term and user strategies. A public topic, a pending topic and a topic in a hidden forum are all unsubscribed, and another user's subscription to the same topic stays.
Supplemental Artifacts
I ran these cases as unit tests, not in a browser. The patch adds tests/phpunit/testcases/users/functions/topic-subscriptions-removal.php (12 tests) for the results above. They also check that nothing happens when subscriptions are disabled, that only the displayed user sees the form and its nonce is accepted by the handler, and the success notice.
All runs except the full suite use --filter BBP_Tests_Users_Functions_Topic_Subscriptions_Removal.
| Run | Result |
| Trunk | 11 errors (new functions missing), 1 failure (no form) |
| Patch | OK (12 tests, 130 assertions) |
| Patch, multisite | OK (12 tests, 130 assertions) |
Patch, with bbp_remove_user_from_all_objects( $user_id, '_bbp_subscription' ) in the new function | 6 failures: forum subscriptions are removed (meta and term strategies, handler and form tests), and a lone forum subscription is removed when there are no topic subscriptions |
| Patch, without removing the forum visibility action | 6 failures: the topic in the hidden forum stays subscribed (all strategies, own user, administrator, form) |
| Patch, full suite | 2456 tests, 11558 assertions, 43 skipped, 1 failure: test_bbp_set_current_anonymous_user_data, a cURL timeout to its local PHP test server. It times out on trunk too, in 2 of 5 runs here
|
Additional Notes
- The handler,
bbp_remove_all_topic_subscriptions_handler(), runs onbbp_post_requestfor thebbp-remove-all-topic-subscriptionsaction. It checks the user specific nonceremove-all-topic-subscriptions_{$user_id}, thenbbp_current_user_can_manage_engagements( 'subscription', $user_id ), which allows the displayed user or a user who canedit_user.bbp_notice_remove_all_topic_subscriptions_success()shows the success notice. - The new template part
form-user-topic-subscriptions.phpis loaded byuser-subscriptions.phponly whenbbp_get_user_topic_subscriptions()finds topics, inside the existingbbp_current_user_can_manage_engagements()check. It says that forum subscriptions are not changed, and the button asks for confirmation, like the topic tag Delete form. The patch also adds aCHANGELOG.mdentry. - Only the user strategy keeps forum subscriptions with
bbp_remove_user_from_all_objects(), because it stores topic subscriptions in their own_bbp_subscriptionsuser option. So the new function gets the subscribed topic IDs frombbp_get_user_object_query(), the relationship query that the Subscriptions screen uses, which works with all three strategies. The query is limited to the topic post type, in any status. Then it callsbbp_remove_user_subscription()for each topic, so thebbp_remove_user_subscriptionaction still runs. - During that query it removes
bbp_pre_get_posts_normalize_forum_visibility, likebbp_repair_forum_visibility()does, so subscriptions to topics in forums the user can no longer read are removed too.bbp_current_user_can_toggle_engagement()already allows removing those. - The BuddyPress member Subscriptions screen loads the same template, so the form shows there too. I did not test it there, and bbPress notices are not printed on BuddyPress member pages.
Thanks @johnjamesjacoby for the detailed spec.
AI assistance: Yes. I used an AI assistant to help investigate and draft this; I ran and checked every test and result myself.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Add an "Unsubscribe from all topics" form and handler to the profile Subscriptions screen (topic subscriptions only), with unit tests.