-
Notifications
You must be signed in to change notification settings - Fork 23
Feature/multiple posttype UI #102
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,7 +35,7 @@ public function get_relationship_key( $from, $to, $name ) { | |
| sort( $to ); | ||
| $to = implode( '.', $to ); | ||
|
|
||
| return "{$from}_{$to}_{$name}"; | ||
| return "{$from}~{$to}~{$name}"; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -70,6 +70,20 @@ public function get_post_to_post_relationship_by_key( $key ) { | |
| return $this->post_post_relationships[ $key ]; | ||
| } | ||
|
|
||
| // Fuzzy match the relationship by parsing the key and looping through the relationships | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Truthfully, I'm not in love with the fuzzy match. I think this could break down if a post type name contained the name of another post type. ex: "post" and "postcard". The challenge here is that the relationship name needs to be able to be constructed, however when the post type is one of the "many" set, it does not have knowledge of it's siblings and the key can not be constructed properly. |
||
| foreach ( $this->post_post_relationships as $relationship_key => $relationship ) { | ||
| $relationship_key_parts = explode( '~', $relationship_key ); | ||
| $key_parts = explode( '~', $key ); | ||
|
|
||
| if ( | ||
| $key_parts[0] === $relationship_key_parts[0] && | ||
| strpos( $relationship_key_parts[1], $key_parts[1] ) !== false && | ||
| $key_parts[2] === $relationship_key_parts[2] | ||
| ) { | ||
| return $this->post_post_relationships[ $relationship_key ]; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
|
|
@@ -91,10 +105,6 @@ public function get_post_to_post_relationship( $cpt1, $cpt2, $name ) { | |
| return $relationship; | ||
| } | ||
|
|
||
| // Try the inverse, only if "cpt2" isn't an array | ||
| if ( is_array( $cpt2 ) ) { | ||
| return false; | ||
| } | ||
| $key = $this->get_relationship_key( $cpt2, $cpt1, $name ); | ||
|
|
||
| $relationship = $this->get_post_to_post_relationship_by_key( $key ); | ||
|
|
||
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.
Switched to a more obscure delimiter to avoid confusion with underscores in post type names.