Respect signal hold during admin AJAX requests (#4097)
Summary:
Description
WordPress reports visitor-facing
admin-ajax.phprequests as admin context. The existing signals-hold check exempted all admin requests, so an AJAX form submission could send a CAPI event while browser delivery remained held.This change centralizes request classification in
FacebookSignalsStateand makes admin AJAX respect the visitor hold while preserving the exemptions for actual admin screens, cron jobs, and physical-store events.No dependencies are required.
Type of change
- Fix (non-breaking change which fixes an issue)
Checklist
- I have commented my code, particularly in hard-to-understand areas, if any.
- I have confirmed that my changes do not introduce any new PHPCS warnings or errors.
- I have checked plugin debug logs that my changes do not introduce any new PHP warnings or FATAL errors.
- I followed general Pull Request best practices.
- I have added regression coverage for the admin AJAX path.
- I have completed dogfooding and QA testing.
- No plugin documentation change is required for this implementation fix.
Changelog entry
Fix signal-hold enforcement for visitor-facing AJAX events.
Pull Request resolved: https://github.com/facebook/facebook-for-woocommerce/pull/4097
Test Plan: Automated verification performed locally:
composer lintphp -lon all changed PHP files- Focused executable classification harness:
- held frontend request: suppressed
- held admin AJAX request: suppressed
- held admin screen: exempt
- held cron request: exempt
The added PHPUnit regression test can be reproduced in the repository’s WordPress test environment:
- Put signals into the held state.
- Set an admin screen and make
wp_doing_ajaxreturn true.- send a website event through
send_api_event().- Verify the event is queued rather than sent.
The local checkout did not have the external WordPress test library/database required by the WooCommerce PHPUnit bootstrap, so that integration test is left to the repository CI environment.
Screenshots
Not applicable; this is a server-side request-classification fix.
Reviewed By: atuld123
Differential Revision: D126289554
Pulled By: vahidkay-meta
fbshipit-source-id: c5319dc0bda5eb48163edb2311e49fc6b1f62ab0
版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9
京公网安备 11010802047560号
Meta for WooCommerce, formerly Facebook for WooCommerce, is now an official plugin from Meta.
We’re excited to announce that the plugin is is now owned by Meta, and we invite the developer community to join us in shaping its future through contributions.
Grow your business on Facebook, Instagram and WhatsApp. Easily promote your products and target accurately using powerful sales and marketing tools. Update your customers about their orders on WhatsApp at every step, freeing up more time for you to focus on your business. Reach new customers and drive traffic to your website with seamless ad experiences, from discovery to conversion. Automatically sync your eligible products to your Meta catalog, so you can easily create ads right where your customers are.
This is the development repository for the Meta for WooCommerce plugin.
Support
Please first take a look at the Meta helpcenter docs, by searching for keywords like ‘WooCommerce’ here. If you didn’t find what you were looking for, you can go to Meta direct support and ask your question.
If you have a WooCommerce.com account, you can search for help or submit a help request on WooCommerce.com.
Logging
The plugin offers logging that can help debug various problems. You can enable debug mode in the main plugin settings panel under the
Enable debug modesection. By default plugin omits headers in the requests to make the logs more readable. If debugging with headers is necessary you can enable the headers in the logs by settingwc_facebook_request_headers_in_debug_logoption to true.Crash recovery limitation (known gap)
Crash recovery uses a shutdown handler to write a disable flag and queue a sanitized crash report. In rare PHP memory-exhaustion fatals, the process may not have enough memory left to run the shutdown handler. When that happens, the site still recovers on the next request, but the disable flag and crash report may be skipped for that request.
Documentation
Development
Developing
wp-content/plugins/folder your WooCommerce development environment.npm installcomposer installnpm startto build a development versionnpm run lint:phpto run PHPCS linter on all PHP files./bin/install-wp-tests.sh <test-db-name> <db-user> <db-password> [db-host]to set up testing environmentnpm run test:phpto run PHP unit tests on all PHP files./vendor/bin/phpunit --coverage-html=reports/coverageto run PHP unit tests with coverageRunning E2E tests locally (events flow)
Use the helper script at
tests/e2e/scripts/run-local-events.sh.Before running it, export all required environment variables (the script reads values directly from your process environment):
Then run:
Optional flags:
Production build
npm run build: Builds a production version.Releasing
Refer to the wiki for details of how to build and release the plugin.
PHPCS Linting and PHP 8.1+
We currently do not support PHPCS on PHP 8.1+ versions. Please run PHPCS checks on PHP 8.0 or lower versions. Refer #2624 PR for additional context.
License
Meta for WooCommerce is licensed under the GNU General Public License v2.0 (or later).
See the LICENSE file for the full license text.