feat(plugin-repo): Add privacy policy content check#1291
Conversation
Add a new Privacy_Policy_Check that warns when a plugin uses personal-data-handling APIs but does not call wp_add_privacy_policy_content(). WordPress.org guidelines require plugins that collect, store, or transmit personal data to a third party to suggest privacy policy text to site administrators via this function. The check scans PHP files for signals indicating potential personal data handling: - wp_remote_post() / wp_remote_get() (external data transmission) - setcookie() / $_COOKIE (cookie-based tracking) - wp_set_auth_cookie() (authentication cookies) If any signal is detected and wp_add_privacy_policy_content() is not called anywhere in the plugin, a single warning is emitted on the plugin's main file pointing to the official WordPress privacy developer documentation. Plugins with no signals are completely unaffected by this check. Fixes WordPress#1249
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
The plugin description contained wp_add_privacy_policy_content() with parentheses, which caused the check's detection regex to match the comment string and return early as if the function was already implemented — producing no warning and failing the test. The description now reads 'does not register privacy policy content' which avoids the false positive without changing the intent of the test fixture.
|
Thanks for the PR! I'm reviewing. |
|
Thanks for the PR! The intent makes sense, but I think this needs one more pass before merging. The check currently scans raw PHP file contents with regexes, so it matches function names in comments and strings as if they were real code. That creates both false negatives and false positives:
This also affects the current “without errors” fixture, because the plugin header description contains Could we update the detection to ignore comments and strings, for example by using |
Replace regex scanning with token_get_all() so function names and variables in comments and string literals no longer trigger false positives or hide real signals. Add fixtures and tests for comment-only and string-only mentions.
|
Thanks for the review. Good catch on the regex. I moved the detection from regex to token parsing with What changed:
All checks pass locally: PHPUnit, PHPCS (WordPress + PHPCompatibility), and PHPStan. Pushed in d025f52. |
Summary
Implements the feature requested in #1249.
WordPress.org guidelines require that every plugin which collects, uses, stores, or passes personal data to a third party must suggest privacy policy text to site administrators using
wp_add_privacy_policy_content(). In practice, the vast majority of plugins that handle personal data do not implement this.This PR adds a new
Privacy_Policy_Check(static file check) that detects common personal-data-handling signals and warns ifwp_add_privacy_policy_content()is absent.How it works
The check scans all PHP files in the plugin for signals that indicate potential personal data handling:
wp_remote_post()wp_remote_get()setcookie()$_COOKIEwp_set_auth_cookie()If any signal is found and
wp_add_privacy_policy_content()is not called anywhere in the plugin, a single warning (severity 5) is emitted on the plugin's main file with a link to the WordPress privacy developer docs.Plugins with no signals are completely unaffected — the check stays silent.
Design decisions
wp_add_privacy_policy_content()first; if present, skips all signal scanning$_POST/$_GETFiles changed
includes/Checker/Checks/Plugin_Repo/Privacy_Policy_Check.php— new check classincludes/Checker/Default_Check_Repository.php— register asprivacy_policydocs/checks.md— add row to the checks tabletests/phpunit/tests/Checker/Checks/Privacy_Policy_Check_Tests.php— 3 test casestests/phpunit/testdata/plugins/test-plugin-privacy-policy-with-errors/— has signal, no privacy call → triggers warningtests/phpunit/testdata/plugins/test-plugin-privacy-policy-without-errors/— has signal +wp_add_privacy_policy_content()→ cleantests/phpunit/testdata/plugins/test-plugin-privacy-policy-no-signals/— no signals → cleanTesting
Manually verified against Mailchimp for WordPress (mc4wp) — correctly fires the
missing_privacy_policy_contentwarning onmailchimp-for-wp.php.Verified against Akismet (which properly calls
wp_add_privacy_policy_content()) — no warning produced.Closes #1249