Custom Posts: Support "Access" and "Email to Subscribers" options#25574
Conversation
|
| App Name | WordPress | |
| Configuration | Release-Alpha | |
| Build Number | 32655 | |
| Version | PR #25574 | |
| Bundle ID | org.wordpress.alpha | |
| Commit | 167830b | |
| Installation URL | 080be8ou8uarg |
|
| App Name | Jetpack | |
| Configuration | Release-Alpha | |
| Build Number | 32655 | |
| Version | PR #25574 | |
| Bundle ID | com.jetpack.alpha | |
| Commit | 167830b | |
| Installation URL | 6hjqjsk1tcov8 |
🤖 Build Failure AnalysisThis build has failures. Claude has analyzed them - check the build annotations for details. |
3d5e892 to
69a0772
Compare
| func shouldShow(_ row: PostSettingsRow) -> Bool { | ||
| // FIXME: meta support missing in AnyPostWithEditContext | ||
| switch row { | ||
| case .jetpackAccessLevel: |
There was a problem hiding this comment.
Should we gate these on whether it's a blog post or not? Pages aren't supported, right?
There was a problem hiding this comment.
Good catch. That's a bug in the production app, too. Addressed in a0deade.
The Jetpack plugin registers the newsletter access and email metas for the "post" type only, so pages should not show these rows. This matches the isPost check that CustomPostSettingsViewModel already applies.
a0deade to
adfeaec
Compare
|
Rebased without any changes |
| switch row { | ||
| case .jetpackAccessLevel: | ||
| return blog.supports(.wpComRESTAPI) | ||
| return isPost && blog.supports(.jetpackNewsletter) |
There was a problem hiding this comment.
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:
accessLevelShownForPostis a positive control — it proves thewithAnAccount().with(modules: ["subscriptions"])blog actually supports newsletter, so the two Page assertions fail for the post-type reason. They go red if theisPost &&here is reverted.page.blog = blogmatters —PageBuilderotherwise builds its own accountless blog, which would make the Page tests pass vacuously (newsletter unsupported regardless of post type).
There was a problem hiding this comment.
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.


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:
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".