Skip to content

Custom Posts: Support "Access" and "Email to Subscribers" options#25574

Merged
crazytonyli merged 10 commits into
trunkfrom
task/cmm-2069-jetpack-post-settings
Jun 17, 2026
Merged

Custom Posts: Support "Access" and "Email to Subscribers" options#25574
crazytonyli merged 10 commits into
trunkfrom
task/cmm-2069-jetpack-post-settings

Conversation

@crazytonyli

Copy link
Copy Markdown
Contributor

Note

I recommend reviewing by commits. The first commit is pure code format changes and can be ignored.

Description

Fixes https://linear.app/a8c/issue/CMM-2069.

Custom Posts settings now support the same Jetpack newsletter options as regular Posts:

  1. The Access section shows the Jetpack newsletter access level.
  2. The Publish sheet shows "Email to Subscribers".
  3. The selected access level and email setting are read from and written back to REST meta.

This PR also fixes a bug where these two options remain visible even when the "Subscriptions" Jetpack module is not activated.

Testing instructions

"Subscriptions" Jetpack module must be activated, which is the case for all simple sites. For jetpack sites, you'll need to go to the Newsletter -> turn on "Let visitors subscribe to this site and receive emails when you publish a post".

@crazytonyli crazytonyli added this to the 27.0 milestone May 21, 2026
@crazytonyli crazytonyli requested a review from jkmassel May 21, 2026 01:00
@crazytonyli crazytonyli changed the title Task/cmm 2069 jetpack post settings Support "Access" and "Email to subscribers" options May 21, 2026
@crazytonyli crazytonyli changed the title Support "Access" and "Email to subscribers" options Custom Posts: Support "Access" and "Email to Subscribers" options May 21, 2026
@wpmobilebot

wpmobilebot commented May 21, 2026

Copy link
Copy Markdown
Contributor
App Icon📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress
ConfigurationRelease-Alpha
Build Number32655
VersionPR #25574
Bundle IDorg.wordpress.alpha
Commit167830b
Installation URL080be8ou8uarg
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot

wpmobilebot commented May 21, 2026

Copy link
Copy Markdown
Contributor
App Icon📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack
ConfigurationRelease-Alpha
Build Number32655
VersionPR #25574
Bundle IDcom.jetpack.alpha
Commit167830b
Installation URL6hjqjsk1tcov8
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot

wpmobilebot commented May 21, 2026

Copy link
Copy Markdown
Contributor

🤖 Build Failure Analysis

This build has failures. Claude has analyzed them - check the build annotations for details.

@crazytonyli crazytonyli force-pushed the task/cmm-2069-jetpack-post-settings branch 2 times, most recently from 3d5e892 to 69a0772 Compare May 26, 2026 22:23
func shouldShow(_ row: PostSettingsRow) -> Bool {
// FIXME: meta support missing in AnyPostWithEditContext
switch row {
case .jetpackAccessLevel:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we gate these on whether it's a blog post or not? Pages aren't supported, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch. That's a bug in the production app, too. Addressed in a0deade.

@crazytonyli crazytonyli force-pushed the task/cmm-2069-jetpack-post-settings branch from a0deade to adfeaec Compare June 14, 2026 22:40
@dangermattic

Copy link
Copy Markdown
Collaborator
1 Warning
⚠️ This PR is assigned to the milestone 27.0. This milestone is due in less than 4 days.
Please make sure to get it merged by then or assign it to a milestone with a later deadline.

Generated by 🚫 Danger

@crazytonyli

Copy link
Copy Markdown
Contributor Author

Rebased without any changes

@crazytonyli crazytonyli requested a review from jkmassel June 14, 2026 22:40
switch row {
case .jetpackAccessLevel:
return blog.supports(.wpComRESTAPI)
return isPost && blog.supports(.jetpackNewsletter)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This isPost && gate matches the CustomPostSettingsViewModel path — but unlike that side (which has shouldShowAccessLevelFalseForNonPost / shouldShowNewsletterFalseForNonPost), the legacy VM landed the gate without a regression test. Here's a symmetric one so a future refactor can't silently re-expose these rows on Pages.

New file — Tests/KeystoneTests/Tests/Features/Posts/PostSettingsViewModelTests.swift:

import Testing
import CoreData
import Foundation

@testable import WordPress
@testable import WordPressData

@MainActor
struct PostSettingsViewModelTests {

    // MARK: - shouldShow Jetpack newsletter rows (post-type gating)

    /// Positive control: proves the blog setup actually enables newsletter, so
    /// the Page assertions below fail for the *post-type* reason, not because
    /// of a mis-configured blog.
    @Test("shouldShow .jetpackAccessLevel is true for a Post on a newsletter site")
    func accessLevelShownForPost() throws {
        let context = ContextManager.forTesting().mainContext
        let blog = newsletterBlog(context)
        let post = PostBuilder(context, blog: blog).build()
        try context.save()

        let viewModel = PostSettingsViewModel(post: post)
        #expect(viewModel.shouldShow(.jetpackAccessLevel))
    }

    @Test("shouldShow .jetpackAccessLevel is false for a Page even on a newsletter site")
    func accessLevelHiddenForPage() throws {
        let context = ContextManager.forTesting().mainContext
        let blog = newsletterBlog(context)
        let page = PageBuilder(context).build()
        page.blog = blog // put the page on the newsletter-capable blog
        try context.save()

        let viewModel = PostSettingsViewModel(post: page)
        #expect(!viewModel.shouldShow(.jetpackAccessLevel))
    }

    @Test("shouldShow .jetpackNewsletterEmailOptions is false for a Page in publishing context")
    func newsletterEmailHiddenForPage() throws {
        let context = ContextManager.forTesting().mainContext
        let blog = newsletterBlog(context)
        let page = PageBuilder(context).build()
        page.blog = blog
        try context.save()

        let viewModel = PostSettingsViewModel(post: page, context: .publishing)
        #expect(!viewModel.shouldShow(.jetpackNewsletterEmailOptions))
    }
}

private func newsletterBlog(_ context: NSManagedObjectContext) -> Blog {
    BlogBuilder(context)
        .withAnAccount()
        .with(modules: ["subscriptions"])
        .build()
}

Verified locally — builds and passes 3/3 on an iPhone 17 Pro sim. Two notes on why it's written this way:

  • accessLevelShownForPost is a positive control — it proves the withAnAccount().with(modules: ["subscriptions"]) blog actually supports newsletter, so the two Page assertions fail for the post-type reason. They go red if the isPost && here is reverted.
  • page.blog = blog mattersPageBuilder otherwise builds its own accountless blog, which would make the Page tests pass vacuously (newsletter unsupported regardless of post type).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The new tests have been added to 167830b

The legacy PostSettingsViewModel.shouldShow post-type gate landed without coverage, unlike the CustomPostSettingsViewModel path. These tests assert the Jetpack access level and newsletter rows are shown for posts but hidden for pages, with positive controls so the page assertions fail for the post-type reason rather than a mis-configured blog.
@crazytonyli crazytonyli requested a review from jkmassel June 16, 2026 00:56
@crazytonyli crazytonyli added this pull request to the merge queue Jun 17, 2026
Merged via the queue into trunk with commit 3867cc4 Jun 17, 2026
24 checks passed
@crazytonyli crazytonyli deleted the task/cmm-2069-jetpack-post-settings branch June 17, 2026 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants