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

Commit 637195c

Browse files
authored
Merge pull request #165 from wordpress-mobile/feature/fix-publishing-private-xmlrpc-posts
Fix publishing private XML-RPC posts.
2 parents 5a0b621 + 7e52f67 commit 637195c

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

WordPressKit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "WordPressKit"
3-
s.version = "4.2.0-beta.2"
3+
s.version = "4.2.0-beta.3"
44
s.summary = "WordPressKit offers a clean and simple WordPress.com and WordPress.org API."
55

66
s.description = <<-DESC

WordPressKit/PostServiceRemoteXMLRPC.m

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,6 @@ - (NSDictionary *)parametersWithRemotePost:(RemotePost *)post
418418
postParams[@"custom_fields"] = post.metadata;
419419
}
420420

421-
if (post.isStickyPost != nil) {
422-
postParams[@"sticky"] = post.isStickyPost.boolValue ? @"true" : @"false";
423-
}
424-
425421
postParams[@"wp_page_parent_id"] = post.parentID ? post.parentID.stringValue : @"0";
426422

427423
// Scheduled posts need to sync with a status of 'publish'.
@@ -433,6 +429,21 @@ - (NSDictionary *)parametersWithRemotePost:(RemotePost *)post
433429
post.status = PostStatusPublish;
434430
}
435431

432+
// At least as of 5.2.2, Private and/or Password Protected posts can't be stickied.
433+
// However, the code used on the backend doesn't check the value of the `sticky` field,
434+
// instead doing a simple `! empty( $post_data['sticky'] )` check.
435+
//
436+
// This means we have to omit this field entirely for those posts from the payload we're sending
437+
// to the XML-RPC sevices.
438+
//
439+
// https://github.com/WordPress/WordPress/blob/master/wp-includes/class-wp-xmlrpc-server.php
440+
//
441+
BOOL shouldIncludeStickyField = ![post.status isEqualToString:PostStatusPrivate] && post.password == nil;
442+
443+
if (post.isStickyPost != nil && shouldIncludeStickyField) {
444+
postParams[@"sticky"] = post.isStickyPost.boolValue ? @"true" : @"false";
445+
}
446+
436447
if ([post.type isEqualToString:@"page"]) {
437448
[postParams setObject:post.status forKey:@"page_status"];
438449
}

0 commit comments

Comments
 (0)