feat: fallback to post type slug for parent page - #37
Conversation
|
Coverage report for commit: ef81625 Summary - Lines: - | Methods: -
🤖 comment via lucassabreu/comment-coverage-clover |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Pull request overview
Adds a fallback mechanism in the breadcrumb parent-page resolution logic so that when an explicit parent-page support slug is not configured, the code attempts to derive the parent page from the post type’s rewrite slug.
Changes:
- Update breadcrumb parent page slug detection to fall back to the post type rewrite slug when
parent-pageslug is missing.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| $postType = get_post_type($postId); | ||
| $supports = get_all_post_type_supports($postType); | ||
| $parentPageSlug = $supports['parent-page'][0]['slug'] ?? null; | ||
| $parentPageSlug = $supports['parent-page'][0]['slug'] ?? get_post_type_object($postType)->rewrite['slug'] ?? null; |
There was a problem hiding this comment.
get_post_type_object($postType)->rewrite['slug'] can throw if get_post_type_object() returns null or if rewrite is false/non-array (common for post types registered with rewrite => false). Consider storing the object in a variable and only reading rewrite['slug'] when it’s an array, otherwise fall back to null (or a safe default).
| $parentPageSlug = $supports['parent-page'][0]['slug'] ?? get_post_type_object($postType)->rewrite['slug'] ?? null; | |
| $postTypeObject = get_post_type_object($postType); | |
| $rewriteSlug = is_object($postTypeObject) && is_array($postTypeObject->rewrite) | |
| ? ($postTypeObject->rewrite['slug'] ?? null) | |
| : null; | |
| $parentPageSlug = $supports['parent-page'][0]['slug'] ?? $rewriteSlug; |
See also Brave Hooks