Repository navigation
Post Settings: Support custom taxonomies #24964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import Foundation | ||
| import WordPressKitObjC | ||
|
|
||
| extension RemotePost { | ||
| public static func compare(otherTerms lhs: [String: [String]], withAnother rhs: [String: [String]]) -> Bool { | ||
| guard lhs.count == rhs.count else { return false } | ||
|
|
||
| return lhs.mapValues { Set($0) } == rhs.mapValues { Set($0) } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| #import "RemotePostTerm.h" | ||
|
|
||
| @import NSObject_SafeExpectations; | ||
|
|
||
| @implementation RemotePostTerm | ||
|
|
||
| - (instancetype)initWithXMLRPCResponse:(NSDictionary *)response | ||
| { | ||
| self = [super init]; | ||
| if (self) { | ||
| self.termID = [response numberForKey:@"term_id"]; | ||
| self.name = [response stringForKey:@"name"]; | ||
| self.slug = [response stringForKey:@"slug"]; | ||
| self.taxonomySlug = [response stringForKey:@"taxonomy"]; | ||
| self.termDescription = [response stringForKey:@"description"]; | ||
| self.count = [response numberForKey:@"count"]; | ||
| } | ||
| return self; | ||
| } | ||
|
|
||
| - (instancetype)initWithRESTAPIResponse:(NSDictionary *)response taxonomySlug:(NSString *)taxonomySlug | ||
| { | ||
| self = [super init]; | ||
| if (self) { | ||
| self.termID = [response numberForKey:@"ID"]; | ||
| self.name = [response stringForKey:@"name"]; | ||
| self.slug = [response stringForKey:@"slug"]; | ||
| self.taxonomySlug = taxonomySlug; | ||
| self.termDescription = [response stringForKey:@"description"]; | ||
| self.count = [response numberForKey:@"post_count"]; | ||
| } | ||
| return self; | ||
| } | ||
|
|
||
| - (NSDictionary *)RESTAPIRepresentation | ||
| { | ||
| return @{ | ||
| @"ID": self.termID, | ||
| @"name": self.name, | ||
| @"slug": self.slug, | ||
| @"description": self.termDescription ?: @"", | ||
| @"post_count": self.count | ||
| }; | ||
| } | ||
|
|
||
| + (NSDictionary<NSString *, NSArray<NSString *> *> *)simpleMappingRepresentation:(NSArray<RemotePostTerm *> *)terms | ||
| { | ||
| NSMutableDictionary<NSString *, NSMutableArray<NSString *> *> *dict = [NSMutableDictionary dictionary]; | ||
| for (RemotePostTerm *term in terms) { | ||
| NSMutableArray *termNames = dict[term.taxonomySlug]; | ||
| if (termNames == nil) { | ||
| termNames = [NSMutableArray array]; | ||
| dict[term.taxonomySlug] = termNames; | ||
| } | ||
| [termNames addObject:term.name]; | ||
| } | ||
| return [dict copy]; | ||
| } | ||
|
|
||
| - (NSString *)debugDescription | ||
| { | ||
| NSDictionary *properties = @{ | ||
| @"ID": self.termID, | ||
| @"name": self.name | ||
| }; | ||
| return [NSString stringWithFormat:@"<%@: %p> (%@)", NSStringFromClass([self class]), self, properties]; | ||
| } | ||
|
|
||
| - (NSString *)description | ||
| { | ||
| return [NSString stringWithFormat:@"<%@: %p> %@[%@]", NSStringFromClass([self class]), self, self.name, self.termID]; | ||
| } | ||
|
|
||
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #import <Foundation/Foundation.h> | ||
|
|
||
| NS_ASSUME_NONNULL_BEGIN | ||
|
|
||
| @interface RemotePostTerm : NSObject | ||
|
|
||
| @property (nonatomic, strong) NSNumber *termID; | ||
| @property (nonatomic, strong) NSString *name; | ||
| @property (nonatomic, strong) NSString *slug; | ||
| @property (nonatomic, strong) NSString *taxonomySlug; | ||
| @property (nonatomic, strong) NSString *termDescription; | ||
| @property (nonatomic, strong) NSNumber *count; | ||
|
|
||
| - (instancetype)initWithXMLRPCResponse:(NSDictionary *)response; | ||
| - (instancetype)initWithRESTAPIResponse:(NSDictionary *)response taxonomySlug:(NSString *)taxonomySlug; | ||
|
|
||
| - (NSDictionary *)RESTAPIRepresentation; | ||
|
|
||
| + (NSDictionary<NSString *, NSArray<NSString *> *> *)simpleMappingRepresentation:(NSArray<RemotePostTerm *> *)terms; | ||
|
|
||
| @end | ||
|
|
||
| NS_ASSUME_NONNULL_END |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kean I need to add similar code, like updating the new
otherTermsvariable, assigning its value to another instance, etc. I don't think I missed any places. But can you pay extra attention to reviewing this part? Thanks!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nit) it looks good, but it might be worth adding a convenience
termsproperty/method that would combine tags and other terms to remove some duplication and also simplify encoding.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The duplication is across two types:
RemotePostUpdateParametersandRemotePostCreateParameters, and different encoders (and keys) for XMLRPC and REST API. I'll leave the code as it is for now, for simplicity.