Skip to content
Open
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
44 changes: 34 additions & 10 deletions WordPress/Classes/Services/BlogServiceRemoteCoreREST.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ import WordPressAPIInternal
return
}

// taxonomy-post_format-post-format-[id]
// │ │ │
// │ │ └─ term slug: "post-format-aside"
// │ │ (WP prefixes format terms with "post-format-")
// │ │
// │ └─ taxonomy name: "post_format"
// │
// └─ template type: taxonomy archive
// taxonomy-post_format-post-format-[id]
// │ │ │
// │ │ └─ term slug: "post-format-aside"
// │ │ (WP prefixes format terms with "post-format-")
// │ │
// │ └─ taxonomy name: "post_format"
// │
// └─ template type: taxonomy archive
let slugPrefix = "taxonomy-post_format-post-format-"

var labelsBySlugs: [String: String] = [:]
Expand Down Expand Up @@ -123,14 +123,17 @@ import WordPressAPIInternal
settings.timeFormat = siteSettings.timeFormat
settings.startOfWeek = String(siteSettings.startOfWeek)
settings.postsPerPage = NSNumber(value: siteSettings.postsPerPage)
settings.commentsAllowed = siteSettings.defaultCommentStatus
.map { NSNumber(value: $0.allowsDiscussion) }
settings.pingbackInboundEnabled = siteSettings.defaultPingStatus
.map { NSNumber(value: $0.allowsDiscussion) }
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.

What happens here if the user isn't an admin? (IINM this is the API that's only exposed to admin-level users?)

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 REST API returns 403, so this code block won't be called.


// The following properties are not available from the Core REST API
// site settings endpoint.
settings.privacy = nil
settings.languageID = nil
settings.iconMediaID = nil
settings.gmtOffset = nil
settings.commentsAllowed = nil
settings.commentsBlocklistKeys = nil
settings.commentsCloseAutomatically = nil
settings.commentsCloseAutomaticallyAfterDays = nil
Expand All @@ -145,7 +148,6 @@ import WordPressAPIInternal
settings.commentsSortOrder = nil
settings.commentsThreadingEnabled = nil
settings.commentsThreadingDepth = nil
settings.pingbackInboundEnabled = nil
settings.pingbackOutboundEnabled = nil
settings.relatedPostsAllowed = nil
settings.relatedPostsEnabled = nil
Expand Down Expand Up @@ -199,3 +201,25 @@ private extension RemoteUser {
self.avatarURL = user.avatarUrls?.avatarURL()?.absoluteString
}
}

private extension SiteSettingsCommentStatus {
/// Plugin-defined custom statuses are treated as "allow"; we don't model
/// them and the conservative default for stock WordPress is `.open`.
var allowsDiscussion: Bool {
switch self {
case .open: return true
case .closed: return false
case .custom: return true
}
}
}

private extension SiteSettingsPingStatus {
var allowsDiscussion: Bool {
switch self {
case .open: return true
case .closed: return false
case .custom: return true
}
}
}