This repository was archived by the owner on Sep 15, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +40
-0
lines changed
Sources/WordPressKit/Services Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,12 @@ public protocol PostServiceRemoteExtended: PostServiceRemote {
99 /// - throws: ``PostServiceRemoteUpdatePostError`` or oher underlying errors
1010 /// (see ``WordPressAPIError``)
1111 func patchPost( withID postID: Int , parameters: RemotePostUpdateParameters ) async throws -> RemotePost
12+
13+ /// Permanently deletes a post with the given ID.
14+ ///
15+ /// - throws: ``PostServiceRemoteUpdatePostError`` or oher underlying errors
16+ /// (see ``WordPressAPIError``)
17+ func deletePost( withID postID: Int ) async throws
1218}
1319
1420public enum PostServiceRemoteUpdatePostError : Error {
Original file line number Diff line number Diff line change @@ -28,6 +28,23 @@ extension PostServiceRemoteREST: PostServiceRemoteExtended {
2828 }
2929 }
3030 }
31+
32+ public func deletePost( withID postID: Int ) async throws {
33+ let path = self . path ( forEndpoint: " sites/ \( siteID) /posts/ \( postID) /delete " , withVersion: . _1_1)
34+ let result = await wordPressComRestApi. perform ( . post, URLString: path)
35+ switch result {
36+ case . success:
37+ return
38+ case . failure( let error) :
39+ guard case . endpointError( let error) = error else {
40+ throw error
41+ }
42+ switch error. apiErrorCode ?? " " {
43+ case " unknown_post " : throw PostServiceRemoteUpdatePostError . notFound
44+ default : throw error
45+ }
46+ }
47+ }
3148}
3249
3350// Decodes the post in the background.
Original file line number Diff line number Diff line change @@ -34,6 +34,23 @@ extension PostServiceRemoteXMLRPC: PostServiceRemoteExtended {
3434 }
3535 }
3636
37+ public func deletePost( withID postID: Int ) async throws {
38+ let parameters = xmlrpcArguments ( withExtra: postID) as [ AnyObject ]
39+ let result = await api. call ( method: " wp.deletePost " , parameters: parameters)
40+ switch result {
41+ case . success:
42+ return
43+ case . failure( let error) :
44+ guard case . endpointError( let error) = error else {
45+ throw error
46+ }
47+ switch error. code ?? 0 {
48+ case 404 : throw PostServiceRemoteUpdatePostError . notFound
49+ default : throw error
50+ }
51+ }
52+ }
53+
3754 private func getPost( withID postID: NSNumber ) async throws -> RemotePost {
3855 try await withUnsafeThrowingContinuation { continuation in
3956 getPostWithID ( postID) { post in
You can’t perform that action at this time.
0 commit comments