Skip to content

fix: add AnsPress compatibility guard for wu-ajax product search (issue #171)#396

Merged
superdav42 merged 1 commit intomainfrom
bugfix/anspress-ajax-compatibility
Mar 24, 2026
Merged

fix: add AnsPress compatibility guard for wu-ajax product search (issue #171)#396
superdav42 merged 1 commit intomainfrom
bugfix/anspress-ajax-compatibility

Conversation

@superdav42
Copy link
Copy Markdown
Collaborator

@superdav42 superdav42 commented Mar 24, 2026

Summary

  • Adds WP_Ultimo\Compat\AnsPress_Compat — a new compatibility class that prevents AnsPress from intercepting Ultimate Multisite's Light Ajax requests and causing a fatal error when selecting a product to add to a membership.
  • Registers the compat class in class-wp-ultimo.php alongside the other compat layers.
  • Updates the known-incompatibilities wiki page to document that this conflict is now automatically resolved (no manual action required).

Root cause

AnsPress registers an AJAX dispatcher on the WordPress init hook (AP_Ajax::init() in v4.x, anspress_ajax() in older versions) that calls die() after processing any request it recognises.

Ultimate Multisite's Light Ajax system also fires on init (when wu-when=init) and relies on reaching its own wu_ajax_* action hooks without interference. When both plugins are active, AnsPress's handler runs first and terminates the request before Ultimate Multisite can serve the product-search JSON, producing a fatal/empty-response error in the membership product-selection modal.

Fix

The compat class hooks into plugins_loaded at PHP_INT_MAX (after AnsPress has registered its own hooks) and removes AnsPress's init-time AJAX handlers before they can fire. The guard is a no-op when AnsPress is not active — no performance impact for sites that don't use AnsPress.

Covers both:

  • AnsPress 4.x — class-based AP_Ajax::init() registered on init at priorities 1, 2, and 10
  • AnsPress < 4.x — function-based anspress_ajax() registered on init

Testing

  1. Install and activate AnsPress alongside Ultimate Multisite.
  2. Navigate to Network Admin → Memberships → Edit any membership.
  3. Click "Add Product" — the product search modal should open and the selectize search should return results without a fatal error.
  4. Confirm the product can be added successfully.

Without this fix, step 3 produces a fatal error / empty AJAX response.

Closes #171

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Resolved incompatibility with AnsPress – Question and Answer plugin that could trigger fatal errors when selecting products for membership creation.
    • Ultimate Multisite 2.4.3+ includes an automatic compatibility fix that seamlessly resolves conflicts without requiring manual user intervention.

#171)

AnsPress registers an AJAX dispatcher on the WordPress `init` hook
(AP_Ajax::init()) that calls die() after processing any request it
recognises. Ultimate Multisite's Light Ajax also fires on `init`
(when wu-when=init) and relies on reaching its own action hooks
without interference.

When both plugins are active, AnsPress's handler runs first and
terminates the request before Ultimate Multisite can serve the
product-search JSON, producing a fatal/empty-response error in the
membership product-selection modal (Add Product).

Fix: add `WP_Ultimo\Compat\AnsPress_Compat` which detects wu-ajax
requests and removes AnsPress's conflicting init-time AJAX hooks
(both the class-based AP_Ajax::init() used in AnsPress 4.x and the
legacy anspress_ajax() function used in older versions) before they
can intercept and terminate the request.

The guard is a no-op when AnsPress is not active, so there is no
performance impact for sites that do not use AnsPress.

Also updates the known-incompatibilities wiki page to document that
this conflict is now automatically resolved.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 24, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6cbad448-7d25-485e-a3e3-609f2bb40c80

📥 Commits

Reviewing files that changed from the base of the PR and between 922d85c and adc26d5.

📒 Files selected for processing (3)
  • .wiki/known-incompatibilities-with-other-plugins.md
  • inc/class-wp-ultimo.php
  • inc/compat/class-anspress-compat.php

📝 Walkthrough

Walkthrough

The changes add a compatibility layer for the AnsPress plugin that detects and removes conflicting AJAX dispatcher hooks during Ultimate Multisite AJAX requests, preventing fatal errors when selecting products for membership creation. A new compatibility class is initialized in the main boot sequence, with documentation updated to reflect the automatic fix.

Changes

Cohort / File(s) Summary
Documentation
.wiki/known-incompatibilities-with-other-plugins.md
Added incompatibility entry for AnsPress plugin, documenting the AJAX dispatcher conflict on the init hook and noting the automatic fix included in version 2.4.3+.
Compatibility Integration
inc/class-wp-ultimo.php
Integrated AnsPress_Compat::get_instance() call into the main compatibility boot sequence alongside existing plugin compatibility handlers.
AnsPress Compatibility Implementation
inc/compat/class-anspress-compat.php
New Singleton compatibility class that removes AnsPress AJAX dispatcher hooks during wu-ajax requests, with helper method to safely remove hooks by class and method name.

Sequence Diagram

sequenceDiagram
    participant Client as Ultimate Multisite Request
    participant PL as plugins_loaded Hook
    participant Init as init Hook
    participant AP as AnsPress
    participant AJAX as AJAX Handler
    
    Client->>PL: Fire plugins_loaded
    PL->>PL: Check if AnsPress exists<br/>(AP_Ajax or anspress_ajax())
    Init->>Init: Check if wu-ajax request
    alt wu-ajax request detected
        Init->>AP: Remove AnsPress AJAX hooks<br/>(AP_Ajax::init)
        AP-->>Init: Hooks removed
    else Not wu-ajax request
        Init->>AP: AnsPress hooks remain active
    end
    Client->>AJAX: Process request
    AJAX-->>Client: Response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 A question of hooks, a answer we found,
AnsPress and Ajax were tangled around,
With careful precision we untie the thread,
So memberships flourish, no errors to dread! 🌸

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bugfix/anspress-ajax-compatibility

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@superdav42 superdav42 merged commit b01fc9b into main Mar 24, 2026
9 of 10 checks passed
@github-actions
Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AnsPress – Question and answer – plugin causes fatal

1 participant