Skip to content

fix: return JSON response for user group subscription AJAX saves#874

Merged
GaryJones merged 1 commit intodevelopfrom
fix/user-groups-ajax-save
Jan 7, 2026
Merged

fix: return JSON response for user group subscription AJAX saves#874
GaryJones merged 1 commit intodevelopfrom
fix/user-groups-ajax-save

Conversation

@GaryJones
Copy link
Copy Markdown
Contributor

Summary

  • Fixes AJAX handler for user group subscriptions to return a JSON response
  • Previously, clicking User Groups checkboxes in the Notifications metabox returned an empty response
  • Adds comprehensive integration tests for notifications AJAX functionality

Problem

When clicking on User Groups checkboxes in the Notifications metabox to subscribe/unsubscribe user groups from post notifications, the AJAX request would return an empty response. This caused:

  • No visual feedback in the UI when toggling user groups
  • Changes not persisting until the post was manually saved

The Users AJAX handler correctly returned wp_send_json_success(), but the User Groups path fell through to wp_die() without any response.

Solution

Added wp_send_json_success() response for User Groups AJAX saves, matching the behavior of User subscriptions:

if ( 'following_usergroups[]' === $_POST['ef_notifications_name'] && $groups_enabled ) {
    $this->save_post_following_usergroups( $post, $user_group_ids );

    if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
        wp_send_json_success(
            [
                'subscribers_with_no_access' => [],
                'subscribers_with_no_email'  => [],
            ]
        );
    }
}

Test plan

  • Integration tests added (NotificationsAjaxTest.php) covering:
    • Users AJAX save returns JSON success
    • User Groups AJAX save returns JSON success
    • AJAX save fails with invalid nonce
    • AJAX save fails without capability
    • AJAX save persists user subscriptions
    • AJAX save persists user group subscriptions
  • Manual testing - User Groups checkboxes now show feedback and persist immediately

🤖 Generated with Claude Code

The AJAX handler for user group subscriptions was falling through to wp_die()
without returning a proper JSON response, causing the UI to receive an empty
response when users toggled user group checkboxes in the Notifications metabox.
This prevented proper feedback and meant changes wouldn't persist until the
post was saved manually.

The fix ensures user group AJAX saves return wp_send_json_success() with the
same structure as user subscriptions (empty arrays for no_access and no_email,
since user groups don't have individual warning badges).

Comprehensive integration tests verify both user and user group AJAX saves
return valid JSON responses, handle authentication correctly, and persist
subscriptions as expected.
@GaryJones GaryJones requested a review from a team as a code owner January 7, 2026 12:40
@GaryJones GaryJones self-assigned this Jan 7, 2026
@GaryJones GaryJones added this to the Next milestone Jan 7, 2026
@GaryJones GaryJones merged commit 8681547 into develop Jan 7, 2026
14 checks passed
@GaryJones GaryJones deleted the fix/user-groups-ajax-save branch January 7, 2026 12:45
@GaryJones GaryJones mentioned this pull request Jan 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant