feat(privacy): add check for missing wp_privacy_personal_data_erasers registration - #1293
faisalahammad wants to merge 2 commits into
Conversation
Add a new static check that warns plugin authors when their plugin handles personal data (user meta, comment meta, direct DB writes) but does not register a callback via the wp_privacy_personal_data_erasers filter. - New check class: Personal_Data_Eraser_Check - Registered in Default_Check_Repository under 'personal_data_eraser' - PHPUnit test class with three test cases - Test data plugins (with and without eraser registration) Fixes WordPress#1252
|
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. |
|
This PR still carries a bug that #1292 already fixed: '/\b(?:add_user_meta|update_user_meta|add_comment_meta|update_comment_meta|\$wpdb\s*->\s*(?:insert|update|replace))\s*\(/'The
So direct DB writes — the case #1252 explicitly calls out — are never detected. The PHPUnit fixtures here don't catch it because neither test plugin exercises a A few other things #1292 resolved that apply equally here, since the two checks share a detection strategy:
Given how closely the two checks mirror each other, it may be simplest to land #1292 first and port its scanner across rather than fix these four things independently. |
|
Thanks for the review. I ported the
Added four test fixtures that cover each case. The full PHPUnit suite passes (479 tests). Please re-review. |
Summary
Adds a new static check (
Personal_Data_Eraser_Check) that warns plugin authors when their plugin appears to handle personal data — viaadd_user_meta,update_user_meta,add_comment_meta,update_comment_meta, or direct$wpdbwrites — but does not register a callback via thewp_privacy_personal_data_erasersfilter.Since WordPress 4.9.6, the Personal Data Removal tool lets site administrators honor GDPR erasure requests. Plugins storing personal data are expected to hook into this tool.
Fixes #1252
Changes
includes/Checker/Checks/Plugin_Repo/Personal_Data_Eraser_Check.php(new)Two-step static check: first confirm the plugin has at least one personal-data storage call, then verify whether it registers the
wp_privacy_personal_data_erasersfilter. A warning is only emitted when step 1 matches and step 2 does not — avoiding false positives for plugins that never touch personal data.Detection uses a
token_get_all()token scanner, porting the approach from #1292. It matches real function and$wpdbmethod calls, ignores comments and string literals, and skips files under a top-leveltests/directory.Key constants:
The check is experimental and only runs with
--include-experimental.Warning code:
missing_personal_data_eraserDocs link: https://developer.wordpress.org/plugins/privacy/adding-the-personal-data-eraser-to-your-plugin/
includes/Checker/Default_Check_Repository.phpTesting
Test 1: Plugin stores user meta, no eraser registered → should warn
update_user_meta()without hookingwp_privacy_personal_data_erasersmissing_personal_data_eraseris reported ✅Test 2: Plugin stores user meta and registers an eraser → should pass
update_user_meta()and registers viaadd_filter( 'wp_privacy_personal_data_erasers', ... )missing_personal_data_eraserwarning ✅Test 3: Plugin has no personal data handling → should pass
$wpdbwritesmissing_personal_data_eraserwarning ✅Test 4: Direct
$wpdbwrite → should warn$wpdb->insert()without registering an eraser--include-experimentalmissing_personal_data_eraseris reported ✅Test 5: Eraser registered only in a
tests/directory → should warnupdate_user_meta()but only registers the eraser inside its owntests/folder--include-experimentalmissing_personal_data_eraseris reported ✅PHPUnit test class:
tests/phpunit/tests/Checker/Checks/Personal_Data_Eraser_Check_Tests.phpcovers all cases with dedicated test data plugins.