Skip to content

fix(memberships): force non-empty message to allow wc_memberships_notice_html to fire#4606

Merged
adekbadek merged 1 commit intoreleasefrom
hotfix/missing-memberships-gate
Mar 30, 2026
Merged

fix(memberships): force non-empty message to allow wc_memberships_notice_html to fire#4606
adekbadek merged 1 commit intoreleasefrom
hotfix/missing-memberships-gate

Conversation

@dkoo
Copy link
Copy Markdown
Contributor

@dkoo dkoo commented Mar 30, 2026

All Submissions:

Changes proposed in this Pull Request:

Closes NPPM-2707.

When all WC Memberships message templates are set to empty strings (which is the case when Newspack content gates replace them), the get_message_html() method in WC Memberships skips get_notice_html() entirely. This means the wc_memberships_notice_html filter never fires, so Newspack's content gate is never rendered. The result is that restricted content is truncated but no gate is shown to the reader.

This fix adds a wc_memberships_restricted_message filter that returns a non-breaking space ( ) when the message is empty and a Newspack gate is configured. This ensures get_notice_html() is called, which fires wc_memberships_notice_html, and the gate renders correctly. The placeholder is fully replaced by Newspack's gate HTML in wc_memberships_notice_html().

The filter has three guard clauses to limit its scope:

  • Only intervenes when the message is empty (leaves publisher-configured messages alone)
  • Only applies to content_ message codes (not product discounts etc.)
  • Only activates when a Newspack gate is configured

How to test the changes in this Pull Request:

  1. Ensure WC Memberships 1.28.1 is installed and active with a membership plan that restricts all posts.
  2. Set the WC Memberships message templates to empty strings (this happens automatically when Newspack content gates are configured, or set manually via update_option('wc_memberships_messages', ['content_restricted_message' => '', ...]))
  3. Configure a Newspack content gate (Audience > Access Control > create a gate restricting all posts with registered access).
  4. Log in as a subscriber/reader who does NOT have an active membership in the restricting plan.
  5. Visit a restricted post.

Expected on release (bug): Content is truncated but no gate appears below it.
Expected on this branch (fix): Content is truncated and the memberships gate is rendered below.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@dkoo dkoo self-assigned this Mar 30, 2026
@github-actions
Copy link
Copy Markdown

🎉 This PR is included in version 6.35.2-hotfix-missing-memberships-gate.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@adekbadek adekbadek marked this pull request as ready for review March 30, 2026 14:37
@adekbadek adekbadek requested a review from a team as a code owner March 30, 2026 14:37
Copy link
Copy Markdown
Member

@adekbadek adekbadek left a comment

Choose a reason for hiding this comment

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

Tested locally against WC Memberships 1.28.1. Confirmed the bug on release (content truncated, no gate) and verified the fix on this branch (gate renders correctly).

The approach is sound – the three guard clauses (empty message only, content restriction codes only, Newspack gate present) keep the scope tight. The   placeholder is fully replaced by Newspack's gate HTML in wc_memberships_notice_html(), so it never leaks to the frontend.

One minor note: on product pages, the is_product() check in wc_memberships_notice_html would return the notice unchanged, but the str_contains($message_code, 'content_') guard effectively prevents this since product restriction codes don't contain content_.

@github-actions github-actions bot added the [Status] Approved The pull request has been reviewed and is ready to merge label Mar 30, 2026
@adekbadek adekbadek merged commit 0e6f1c0 into release Mar 30, 2026
17 checks passed
@adekbadek adekbadek deleted the hotfix/missing-memberships-gate branch March 30, 2026 14:56
@github-actions
Copy link
Copy Markdown

Hey @dkoo, good job getting this PR merged! 🎉

Now, the needs-changelog label has been added to it.

Please check if this PR needs to be included in the "Upcoming Changes" and "Release Notes" doc. If it doesn't, simply remove the label.

If it does, please add an entry to our shared document, with screenshots and testing instructions if applicable, then remove the label.

Thank you! ❤️

@github-actions
Copy link
Copy Markdown

🎉 This PR is included in version 6.35.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Status] Approved The pull request has been reviewed and is ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants