Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Traits/ParentPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ private function getParentPagesIds(int $postId): array
return [];
}

$parentPageSlug = get_all_post_type_supports(get_post_type($postId))['parent-page'][0]['slug'] ?? null;
$postType = get_post_type($postId);
$supports = get_all_post_type_supports($postType);
$parentPageSlug = $supports['parent-page'][0]['slug'] ?? get_post_type_object($postType)->rewrite['slug'] ?? null;
Comment on lines +35 to +36
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_post_type_object($postType)->rewrite['slug'] can throw warnings/fatal errors if get_post_type($postId) returns false (invalid post) or if get_post_type_object() returns null, and rewrite can be false (non-rewritten CPT) so array access may warn. Consider guarding for a falsy $postType, storing the post type object in a variable, and only reading $obj->rewrite['slug'] when the object exists and rewrite is an array with a slug key (otherwise fall back to null).

Suggested change
$supports = get_all_post_type_supports($postType);
$parentPageSlug = $supports['parent-page'][0]['slug'] ?? get_post_type_object($postType)->rewrite['slug'] ?? null;
if (! $postType) {
return [];
}
$supports = get_all_post_type_supports($postType);
$postTypeObject = get_post_type_object($postType);
$rewriteSlug = is_object($postTypeObject) && is_array($postTypeObject->rewrite) && isset($postTypeObject->rewrite['slug'])
? $postTypeObject->rewrite['slug']
: null;
$parentPageSlug = $supports['parent-page'][0]['slug'] ?? $rewriteSlug;

Copilot uses AI. Check for mistakes.
$parent = $parentPageSlug ? get_page_by_path($parentPageSlug) : null;
if (! $parent) {
return [];
Expand Down
Loading