Skip to content

fix(reader-data): make is_donor read-only only when platform has server-side tracking#4641

Open
jason10lee wants to merge 4 commits intotrunkfrom
fix/allow-non-woo-is-donor-write
Open

fix(reader-data): make is_donor read-only only when platform has server-side tracking#4641
jason10lee wants to merge 4 commits intotrunkfrom
fix/allow-non-woo-is-donor-write

Conversation

@jason10lee
Copy link
Copy Markdown
Contributor

@jason10lee jason10lee commented Apr 7, 2026

Changes proposed:

The is_donor reader data key was made unconditionally read-only in #4532, which broke a Campaigns feature that sets is_donor client-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_donor conditionally read-only based on whether the donation platform has server-side donor tracking:

  • WooCommerce sites: is_donor remains read-only. The donation_new data event handles it server-side.
  • NRH / other sites: is_donor is 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_donor is not read-only, any authenticated reader can set it via the REST API. This is an intentional trade-off documented in the code — is_donor is used for segmentation and analytics, not access control. Consumers that need to distinguish server-verified from client-asserted donor status should check Donations::has_server_side_donor_tracking().

Fixes NPPD-1431: Allow non-Woo integrations to write is_donor.

How to test:

  1. With the donation platform set to WooCommerce (default):

    • Confirm is_donor is in the read-only keys list: in the browser console, check newspack_reader_data.read_only_keys includes is_donor.
    • As a logged-in reader, confirm that window.newspackReaderActivation.store.set('is_donor', true) throws a read-only error.
  2. Switch the donation platform to NRH (Audience > Checkout & Payment):

    • Confirm is_donor is NOT in newspack_reader_data.read_only_keys.
    • As a logged-in reader, confirm that window.newspackReaderActivation.store.set('is_donor', true) succeeds without error.
    • Confirm the value persists in localStorage as np_reader_1_is_donor.

    Note: If switching via WP-CLI (wp option update newspack_reader_revenue_platform nrh), run wp cache flush afterward to clear the autoloaded option cache. Switching via the admin UI flushes the cache automatically. This bit yr. humble dev while he was trying to red/green test, so making a note of it!

@jason10lee jason10lee self-assigned this Apr 7, 2026
@jason10lee jason10lee marked this pull request as ready for review April 7, 2026 22:59
@jason10lee jason10lee requested a review from a team as a code owner April 7, 2026 22:59
@jason10lee jason10lee marked this pull request as draft April 7, 2026 23:00
@jason10lee jason10lee requested a review from Copilot April 7, 2026 23:03
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() include is_donor only when Donations::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.

@jason10lee jason10lee marked this pull request as ready for review April 9, 2026 01:10
@jason10lee jason10lee added the [Status] Needs Review The issue or pull request needs to be reviewed label Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Status] Needs Review The issue or pull request needs to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants