Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
27.2
-----
* [*] Custom Post Types: Make custom post types with REST API and editor support available in My Site [#25849]


27.1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import Testing
import WordPressData

@testable import WordPress

@MainActor
@Suite("CustomPostTypeService")
struct CustomPostTypeServiceTests {
@Test("rejects a WordPress.com Simple site")
func rejectsSimpleSite() {
let contextManager = ContextManager.forTesting()
let blog = BlogBuilder(contextManager.mainContext)
.with(atomic: false)
.isHostedAtWPcom()
.withAnAccount()
.build()

#expect(!blog.supportsCoreRESTAPI)
#expect(CustomPostTypeService(blog: blog) == nil)
}

@Test("accepts a WordPress.com Atomic site")
func acceptsAtomicSite() {
let contextManager = ContextManager.forTesting()
let blog = BlogBuilder(contextManager.mainContext)
.with(atomic: true)
.isHostedAtWPcom()
.withAnAccount()
.build()

#expect(blog.supportsCoreRESTAPI)
#expect(CustomPostTypeService(blog: blog) != nil)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Testing

@testable import WordPress

@Suite("PinnedPostType")
struct PinnedPostTypeTests {
@Test("identifies the built-in post type")
func identifiesPosts() {
#expect(PinnedPostType.posts.isBuiltInPostOrPage)
}

@Test("identifies the built-in page type")
func identifiesPages() {
#expect(PinnedPostType.pages.isBuiltInPostOrPage)
}

@Test("does not identify a custom post type as built-in")
func acceptsCustomPostType() {
let postType = PinnedPostType(slug: "book", name: "Books", icon: nil)

#expect(!postType.isBuiltInPostOrPage)
}
}
4 changes: 0 additions & 4 deletions WordPress/Classes/Utility/BuildInformation/FeatureFlag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public enum FeatureFlag: Int, CaseIterable {
case newSupport
case nativeBlockInserter
case statsAds
case customPostTypes
case mediaLibraryV2

/// Returns a boolean indicating if the feature is enabled.
Expand Down Expand Up @@ -85,8 +84,6 @@ public enum FeatureFlag: Int, CaseIterable {
return true
case .statsAds:
return BuildConfiguration.current == .debug
case .customPostTypes:
return BuildConfiguration.current == .debug
case .mediaLibraryV2:
return BuildConfiguration.current == .debug
}
Expand Down Expand Up @@ -131,7 +128,6 @@ extension FeatureFlag {
case .newSupport: "New Support"
case .nativeBlockInserter: "Native Block Inserter"
case .statsAds: "Stats Ads Tab"
case .customPostTypes: "Custom Post Types"
case .mediaLibraryV2: "Media Library v2"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,9 @@ private extension BlogDetailsTableViewModel {
rows.append(Row.media(viewController: viewController))
rows.append(Row.comments(viewController: viewController))

if FeatureFlag.customPostTypes.enabled && blog.supportsCoreRESTAPI {
if blog.supportsCoreRESTAPI {
let pinned = SiteStorageAccess.pinnedPostTypes(for: TaggedManagedObjectID(blog))
.filter { !$0.isBuiltInPostOrPage }
for type in pinned {
rows.append(Row.pinnedPostType(type, viewController: viewController))
}
Expand Down Expand Up @@ -677,8 +678,9 @@ private extension BlogDetailsTableViewModel {

rows.append(Row.comments(viewController: viewController))

if FeatureFlag.customPostTypes.enabled && blog.supportsCoreRESTAPI {
if blog.supportsCoreRESTAPI {
let pinned = SiteStorageAccess.pinnedPostTypes(for: TaggedManagedObjectID(blog))
.filter { !$0.isBuiltInPostOrPage }
for type in pinned {
rows.append(Row.pinnedPostType(type, viewController: viewController))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CustomPostTypeService {
}

init?(blog: Blog) {
guard FeatureFlag.customPostTypes.enabled, let site = try? WordPressSite(blog: blog) else { return nil }
guard blog.supportsCoreRESTAPI, let site = try? WordPressSite(blog: blog) else { return nil }
self.blog = TaggedManagedObjectID(blog)
self.client = WordPressClientFactory.shared.instance(for: site)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ struct PinnedPostType: Codable, Hashable {
extension PinnedPostType {
// TODO: Ideally use the post type details directly instead of PinnedPostType,
// once the CPT infrastructure is more mature.
var isBuiltInPostOrPage: Bool {
slug == Self.posts.slug || slug == Self.pages.slug
}

static let posts = PinnedPostType(slug: "post", name: "Posts", icon: nil)
static let pages = PinnedPostType(slug: "page", name: "Pages", icon: nil)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class ExperimentalFeaturesDataProvider: ExperimentalFeaturesViewModel.DataProvid
FeatureFlag.intelligence,
FeatureFlag.newStats,
RemoteFeatureFlag.newGutenberg,
FeatureFlag.customPostTypes,
FeatureFlag.newSupport,
]

Expand Down