Skip to content

Refactor upsell logic to include premium subscription validation#23200

Merged
JorPV merged 3 commits intofeature/content-plannerfrom
1177-upsell-modal-shown-unexpectedly-on-premium
Apr 28, 2026
Merged

Refactor upsell logic to include premium subscription validation#23200
JorPV merged 3 commits intofeature/content-plannerfrom
1177-upsell-modal-shown-unexpectedly-on-premium

Conversation

@FAMarfuaty
Copy link
Copy Markdown
Contributor

@FAMarfuaty FAMarfuaty commented Apr 28, 2026

Context

Summary

This PR can be summarized in the following changelog entry:

  • Fixes an unreleased bug where the upsell modal was shown unexpectedly on the Content Planner for Premium users when the monthly spark limit (100) had been previously reached.

Relevant technical choices:

  • The isUsageCountLimitReached selector only checks whether count >= limit without considering whether the user holds a valid Premium subscription. The AI Generator (ai-generator/components/app.js) already handles this correctly via checkSubscriptions(). This fix applies the same pattern to the Content Planner by adding a selectPremiumSubscription() check alongside isUsageCountLimitReached in both the approve modal container and the useFetchContentSuggestions hook.

Test instructions

Test instructions for the acceptance test before the PR gets merged

This PR can be acceptance tested by following these steps:

  • Install and activate Yoast SEO (without Premium enabled).
  • Create or edit a post and use AI features (AI Generator or Content Planner) until you exhaust all 10 free sparks.
  • Verify the upsell modal is shown (expected for free users).
  • Enable Premium (activate a valid Premium subscription).
  • Go to the post again and open the Content Planner feature.
  • Run wp.data.dispatch( "yoast-seo/ai-generator").setUsageCount(100) in the browser console to simulate a high usage count
  • Use the AI Generator 👉🏽 verify it works without showing an upsell modal.
  • Use the Content Planner by clicking on "Get content suggestions" button, verify that:
    • you don't see the upsell modal anymore
    • the suggestions are generated successfully
    • You see "You've used 100 sparks this month." notification

Relevant test scenarios

  • Changes should be tested with the browser console open
  • Changes should be tested on different posts/pages/taxonomies/custom post types/custom taxonomies
  • Changes should be tested on different editors (Default Block/Gutenberg/Classic/Elementor/other)
  • Changes should be tested on different browsers
  • Changes should be tested on multisite

Test instructions for QA when the code is in the RC

  • QA should use the same steps as above.

QA can test this PR by following these steps:

Impact check

This PR affects the following parts of the plugin, which may require extra testing:

  • N/A

Other environments

  • This PR also affects Shopify. I have added a changelog entry starting with [shopify-seo], added test instructions for Shopify and attached the Shopify label to this PR.
  • This PR also affects Yoast SEO for Google Docs. I have added a changelog entry starting with [yoast-doc-extension], added test instructions for Yoast SEO for Google Docs and attached the Google Docs Add-on label to this PR.

Documentation

  • I have written documentation for this change. For example, comments in the Relevant technical choices, comments in the code, documentation on Confluence / shared Google Drive / Yoast developer portal, or other.

Quality assurance

  • I have tested this code to the best of my abilities.
  • During testing, I had activated all plugins that Yoast SEO provides integrations for.
  • I have added unit tests to verify the code works as intended.
  • If any part of the code is behind a feature flag, my test instructions also cover cases where the feature flag is switched off.
  • I have written this PR in accordance with my team's definition of done.
  • I have checked that the base branch is correctly set.
  • I have run grunt build:images and commited the results, if my PR introduces new images or SVGs.

Innovation

  • No innovation project is applicable for this PR.
  • This PR falls under an innovation project. I have attached the innovation label.
  • I have added my hours to the WBSO document.

Fixes #

@FAMarfuaty FAMarfuaty added innovation Innovative issue. Relating to performance, memory or data-flow. changelog: non-user-facing Needs to be included in the 'Non-userfacing' category in the changelog labels Apr 28, 2026
@FAMarfuaty FAMarfuaty added this to the feature/content-planner milestone Apr 28, 2026
@FAMarfuaty FAMarfuaty marked this pull request as ready for review April 28, 2026 09:18
@coveralls
Copy link
Copy Markdown

coveralls commented Apr 28, 2026

Coverage Report for CI Build 67199

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage decreased (-0.002%) to 53.473%

Details

  • Coverage decreased (-0.002%) from the base build.
  • Patch coverage: 5 uncovered changes across 2 files (0 of 5 lines covered, 0.0%).
  • 2 coverage regressions across 2 files.

Uncovered Changes

File Changed Covered %
packages/js/src/ai-content-planner/hooks/use-fetch-content-suggestions.js 3 0 0.0%
packages/js/src/ai-content-planner/containers/approve-modal.js 2 0 0.0%

Coverage Regressions

2 previously-covered lines in 2 files lost coverage.

File Lines Losing Coverage Coverage
packages/js/src/ai-content-planner/containers/approve-modal.js 1 0.0%
packages/js/src/ai-content-planner/hooks/use-fetch-content-suggestions.js 1 3.23%

Coverage Stats

Coverage Status
Relevant Lines: 66023
Covered Lines: 35170
Line Coverage: 53.27%
Relevant Branches: 16928
Covered Branches: 9186
Branch Coverage: 54.27%
Branches in Coverage %: Yes
Coverage Strength: 45561.51 hits per line

💛 - Coveralls

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

Updates the AI Content Planner’s upsell gating so that reaching the spark usage limit no longer triggers the upsell flow for users with a valid Premium subscription, aligning behavior with the AI Generator.

Changes:

  • Add Premium subscription validation (selectPremiumSubscription) to Content Planner upsell decisions.
  • Bypass “usage limit reached” early-exit paths when a valid Premium subscription is present in useFetchContentSuggestions.
  • Add/adjust unit tests around the approve modal behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
packages/js/src/ai-content-planner/hooks/use-fetch-content-suggestions.js Adds Premium subscription check to avoid blocking suggestion fetching when limit is reached for Premium users.
packages/js/src/ai-content-planner/containers/approve-modal.js Updates isUpsell computation to factor in valid Premium subscription state.
packages/js/tests/ai-content-planner/components/approve-modal.test.js Adds tests related to Premium/upsell rendering in the approve modal component.
Comments suppressed due to low confidence (1)

packages/js/src/ai-content-planner/hooks/use-fetch-content-suggestions.js:65

  • The useCallback dependency array is missing setContentSuggestionsStatus, even though it’s used inside the callback. This can lead to a stale closure and also violates the usual hooks dependency conventions in this file (other dispatch fns are included). Add setContentSuggestionsStatus to the dependency list (or restructure so it’s not captured).
	}, [ endpoint,
		postType,
		contentLocale,
		editorApiValue,
		isUsageCountLimitReached,
		hasValidPremiumSubscription,
		usageCountEndpoint,
		fetchContentPlannerSuggestions,
		addUsageCount,
		fetchUsageCount,
		setFeatureModalStatus ] );

Comment thread packages/js/tests/ai-content-planner/components/approve-modal.test.js Outdated
…test.js

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@JorPV
Copy link
Copy Markdown
Contributor

JorPV commented Apr 28, 2026

CR + ACC ✅

@JorPV JorPV merged commit 37cbe61 into feature/content-planner Apr 28, 2026
19 checks passed
@JorPV JorPV deleted the 1177-upsell-modal-shown-unexpectedly-on-premium branch April 28, 2026 11:53
@vraja-pro vraja-pro mentioned this pull request Apr 28, 2026
19 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog: non-user-facing Needs to be included in the 'Non-userfacing' category in the changelog innovation Innovative issue. Relating to performance, memory or data-flow.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants