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

Commit a85abac

Browse files
authored
Add an API to get a post's latest revision id (#637)
2 parents 28174ac + ec7ff3e commit a85abac

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

WordPressKit/PostServiceRemoteREST+Revisions.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,33 @@ public extension PostServiceRemoteREST {
2727
failure(error)
2828
})
2929
}
30+
31+
func getPostLatestRevisionID(for postId: NSNumber, success: @escaping (NSNumber?) -> Void, failure: @escaping (Error?) -> Void) {
32+
let endpoint = "sites/\(siteID)/posts/\(postId)"
33+
let path = self.path(forEndpoint: endpoint, withVersion: ._1_1)
34+
wordPressComRestApi.GET(
35+
path,
36+
parameters: [
37+
"context": "edit",
38+
"fields": "revisions"
39+
] as [String: AnyObject],
40+
success: { (response, _) in
41+
let latestRevision: NSNumber?
42+
if let json = response as? [String: Any],
43+
let revisions = json["revisions"] as? NSArray,
44+
let latest = revisions.firstObject as? NSNumber {
45+
latestRevision = latest
46+
} else {
47+
latestRevision = nil
48+
}
49+
success(latestRevision)
50+
},
51+
failure: { error, _ in
52+
WPKitLogError("\(error)")
53+
failure(error)
54+
}
55+
)
56+
}
3057
}
3158

3259
private extension PostServiceRemoteREST {

0 commit comments

Comments
 (0)