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

Commit b5fb7e1

Browse files
committed
Add fix for broken publishing of private posts when using XML-RPC
1 parent 5a0b621 commit b5fb7e1

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

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)