fix(reader-data): make is_donor read-only only when platform has server-side tracking#4641
Open
jason10lee wants to merge 4 commits intotrunkfrom
Open
fix(reader-data): make is_donor read-only only when platform has server-side tracking#4641jason10lee wants to merge 4 commits intotrunkfrom
jason10lee wants to merge 4 commits intotrunkfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adjusts Reader Data’s is_donor read-only enforcement to depend on whether the active donations platform supports server-side donor tracking, restoring the client-side donor-landing-page flow for non-Woo platforms.
Changes:
- Makes
Reader_Data::get_read_only_keys()includeis_donoronly whenDonations::has_server_side_donor_tracking()is true. - Introduces
Donations::has_server_side_donor_tracking()capability method (currently true for WooCommerce only). - Adds unit tests covering platform-conditional behavior and the read-only-keys filter.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/unit-tests/reader-data-read-only-keys.php | Adds unit tests for platform-conditional is_donor read-only behavior and filter behavior. |
| includes/reader-activation/class-reader-data.php | Builds read-only key list dynamically; conditionally includes is_donor based on server-side tracking capability. |
| includes/class-donations.php | Adds has_server_side_donor_tracking() to centralize the “server-side donor tracking” capability check. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes proposed:
The
is_donorreader data key was made unconditionally read-only in #4532, which broke a Campaigns feature that setsis_donorclient-side on post-transaction landing pages. This mainly affects sites using non-Newspack donation platforms (NRH, other) where there is no server-side path to set the flag.This PR makes
is_donorconditionally read-only based on whether the donation platform has server-side donor tracking:is_donorremains read-only. Thedonation_newdata event handles it server-side.is_donoris writable, allowing the existing client-side landing page flow to work for both anonymous and logged-in readers.The change introduces
Donations::has_server_side_donor_tracking(), a capability method that decouples the policy ("does this platform manage donor status server-side?") from the platform identifier. Future platforms with secure server-side handling add themselves to this one method.Note: when
is_donoris not read-only, any authenticated reader can set it via the REST API. This is an intentional trade-off documented in the code —is_donoris used for segmentation and analytics, not access control. Consumers that need to distinguish server-verified from client-asserted donor status should checkDonations::has_server_side_donor_tracking().Fixes NPPD-1431: Allow non-Woo integrations to write
is_donor.How to test:
With the donation platform set to WooCommerce (default):
is_donoris in the read-only keys list: in the browser console, checknewspack_reader_data.read_only_keysincludesis_donor.window.newspackReaderActivation.store.set('is_donor', true)throws a read-only error.Switch the donation platform to NRH (Audience > Checkout & Payment):
is_donoris NOT innewspack_reader_data.read_only_keys.window.newspackReaderActivation.store.set('is_donor', true)succeeds without error.np_reader_1_is_donor.