Skip to content

MR-10: Allow setting paragraph count before paywall#23

Open
av3nger wants to merge 2 commits into
feature/MR-31-paywallfrom
feature/MR-10-paragraph-count
Open

MR-10: Allow setting paragraph count before paywall#23
av3nger wants to merge 2 commits into
feature/MR-31-paywallfrom
feature/MR-10-paragraph-count

Conversation

@av3nger

@av3nger av3nger commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

Customise how many paragraphs before paywall with global marketing content.

What's included

  • New memberful_paragraph_count option (1–10, default 2), registered in memberful_wp_all_options().
  • New "Paragraphs before paywall" number field on the Global marketing content screen, shown only when "Automatically pull an excerpt" is enabled.
  • The auto-excerpt teaser now reads the option (clamped 1–10) instead of the hardcoded MEMBERFUL_PARAGRAPH_COUNT constant, which is kept as the fallback default.

Test plan

  • On Settings → Memberful → Global marketing content, enable "Automatically pull an excerpt", set "Paragraphs before paywall" to N, save, and confirm the value persists (and that the field shows/hides with the excerpt checkbox).
  • View a protected post with ≥N

    paragraphs and no Paywall Divider block as a logged-out visitor, and confirm exactly N paragraphs appear before the paywall; posts using a Paywall Divider block are unaffected.

  • Confirm out-of-range values clamp on save (0 → 1, 50 → 10).

Note

Low Risk
Marketing/teaser display only; values are sanitized and clamped, with no auth or payment impact.

Overview
Adds a configurable paragraph count (1–10, default 2) for the “automatically pull an excerpt” global marketing flow, replacing the fixed MEMBERFUL_PARAGRAPH_COUNT loop limit at runtime.

Site admins get a “Paragraphs before paywall” number field on Global marketing content, visible only when the excerpt checkbox is on; saves clamp the value to 1–10 via memberful_paragraph_count. Copy and admin CSS were updated to match existing paywall builder field styling.

Reviewed by Cursor Bugbot for commit 0761b85. Bugbot is set up for automated code reviews on this repo. Configure here.

@av3nger av3nger changed the title Allow setting paragraph count before paywall MR-10: Allow setting paragraph count before paywall Jul 1, 2026
@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a configurable memberful_paragraph_count option (default 2, clamped 1–10) that determines how many opening paragraphs display before the paywall in global marketing teasers. Wires the setting through defaults, admin save/render logic, the content filter loop, the settings view UI, and admin CSS styling.

Changes

Configurable Paragraph Count

Layer / File(s) Summary
Default option value
src/options.php
Adds memberful_paragraph_count default of 2 to plugin option defaults.
Admin save and render logic
src/admin.php
Saves sanitized/clamped (1–10) memberful_paragraph_count on form submit and passes the retrieved value (default 2) to the render template.
Teaser paragraph filter logic
src/global_marketing.php
Replaces the fixed MEMBERFUL_PARAGRAPH_COUNT loop bound with a dynamic, clamped (1–10) count derived from the option.
Settings view UI and styling
views/global_marketing.php, stylesheets/admin.css
Updates PHPDoc and help text, adds a conditional "Paragraphs before paywall" numeric input, and adds matching CSS for the new field.

Sequence Diagram(s)

sequenceDiagram
  participant Admin
  participant memberful_wp_global_marketing
  participant WordPressOptions
  participant global_marketing_filter as memberful_apply_global_snippets_content_filter

  Admin->>memberful_wp_global_marketing: submit save_global_marketing
  memberful_wp_global_marketing->>memberful_wp_global_marketing: sanitize & clamp paragraph count (1-10)
  memberful_wp_global_marketing->>WordPressOptions: update_option memberful_paragraph_count
  Admin->>memberful_wp_global_marketing: view global_marketing page
  memberful_wp_global_marketing->>WordPressOptions: get_option memberful_paragraph_count (default 2)
  memberful_wp_global_marketing->>Admin: render form with paragraph_count field
  global_marketing_filter->>WordPressOptions: get_option memberful_paragraph_count (default MEMBERFUL_PARAGRAPH_COUNT)
  global_marketing_filter->>global_marketing_filter: clamp value (1-10) and build teaser loop
Loading

Possibly related PRs

  • TheCodeCompany/memberful-wp#8: Both PRs modify memberful_apply_global_snippets_content_filter() in src/global_marketing.php, altering the teaser paragraph generation logic.

Poem

A rabbit hopped through paragraphs two,
then stretched the count from one up to ten new,
a knob in the admin, a style to match,
before the paywall, teasers now attach.
🐇📄✨ configurable, snug and true.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: making the pre-paywall paragraph count configurable.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The description matches the PR changes, covering the new paragraph count option, admin field, and teaser behavior.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/MR-10-paragraph-count

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@wordpress/wp-content/plugins/memberful-wp/views/global_marketing.php`:
- Around line 56-61: The displayed value in global_marketing.php is only clamped
with the lower bound in the paragraph count input, so it can render above the
field’s max when the stored option is too large. Update the value handling in
the paragraph count input to clamp both bounds before echoing it, matching the
existing save-time and filter-time behavior in the memberful paragraph count
logic.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: TheCodeCompany/coderabbit/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 8d1ce49a-09ef-41fa-b834-5f5491f6011b

📥 Commits

Reviewing files that changed from the base of the PR and between 7973d05 and 75a8798.

📒 Files selected for processing (5)
  • wordpress/wp-content/plugins/memberful-wp/src/admin.php
  • wordpress/wp-content/plugins/memberful-wp/src/global_marketing.php
  • wordpress/wp-content/plugins/memberful-wp/src/options.php
  • wordpress/wp-content/plugins/memberful-wp/stylesheets/admin.css
  • wordpress/wp-content/plugins/memberful-wp/views/global_marketing.php

@zhickson

zhickson commented Jul 1, 2026

Copy link
Copy Markdown
Member

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants