Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit 7c7439b

Browse files
authored
Offline Mode: Fix encoding for some fields in the new XMLRPC endpoints (#786)
2 parents 7b624cd + 0900789 commit 7c7439b

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

Sources/WordPressKit/Models/RemotePostParameters.swift

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public struct RemotePostUpdateParameters: Equatable {
3535
public var ifNotModifiedSince: Date?
3636

3737
public var status: String?
38-
public var date: Date??
39-
public var authorID: Int??
38+
public var date: Date?
39+
public var authorID: Int?
4040
public var title: String??
4141
public var content: String??
4242
public var password: String??
@@ -396,11 +396,11 @@ struct RemotePostUpdateParametersXMLRPCEncoder: Encodable {
396396
try container.encodeIfPresent(parameters.status, forKey: .postStatus)
397397
try container.encodeIfPresent(parameters.date, forKey: .date)
398398
try container.encodeIfPresent(parameters.authorID, forKey: .authorID)
399-
try container.encodeIfPresent(parameters.title, forKey: .title)
400-
try container.encodeIfPresent(parameters.content, forKey: .content)
401-
try container.encodeIfPresent(parameters.password, forKey: .password)
402-
try container.encodeIfPresent(parameters.excerpt, forKey: .excerpt)
403-
try container.encodeIfPresent(parameters.slug, forKey: .slug)
399+
try container.encodeStringIfPresent(parameters.title, forKey: .title)
400+
try container.encodeStringIfPresent(parameters.content, forKey: .content)
401+
try container.encodeStringIfPresent(parameters.password, forKey: .password)
402+
try container.encodeStringIfPresent(parameters.excerpt, forKey: .excerpt)
403+
try container.encodeStringIfPresent(parameters.slug, forKey: .slug)
404404
if let value = parameters.featuredImageID {
405405
if let featuredImageID = value {
406406
try container.encode(featuredImageID, forKey: .featuredImageID)
@@ -420,7 +420,7 @@ struct RemotePostUpdateParametersXMLRPCEncoder: Encodable {
420420
}
421421

422422
// Posts
423-
try container.encodeIfPresent(parameters.format, forKey: .format)
423+
try container.encodeStringIfPresent(parameters.format, forKey: .format)
424424
if let tags = parameters.tags {
425425
try container.encode(tags, forKey: .tags)
426426
}
@@ -440,3 +440,10 @@ struct RemotePostUpdateParametersXMLRPCMetadata: Encodable {
440440
self.value = item.value
441441
}
442442
}
443+
444+
private extension KeyedEncodingContainer {
445+
mutating func encodeStringIfPresent(_ value: String??, forKey key: Key) throws {
446+
guard let value else { return }
447+
try encode(value ?? "", forKey: key)
448+
}
449+
}

0 commit comments

Comments
 (0)