fix: add AnsPress compatibility guard for wu-ajax product search (issue #171)#396
Conversation
#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.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe 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
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
🔨 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! Login credentials: |
Summary
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.class-wp-ultimo.phpalongside the other compat layers.Root cause
AnsPress registers an AJAX dispatcher on the WordPress
inithook (AP_Ajax::init()in v4.x,anspress_ajax()in older versions) that callsdie()after processing any request it recognises.Ultimate Multisite's Light Ajax system also fires on
init(whenwu-when=init) and relies on reaching its ownwu_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_loadedatPHP_INT_MAX(after AnsPress has registered its own hooks) and removes AnsPress'sinit-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:
AP_Ajax::init()registered oninitat priorities 1, 2, and 10anspress_ajax()registered oninitTesting
Without this fix, step 3 produces a fatal error / empty AJAX response.
Closes #171
Summary by CodeRabbit
Release Notes