Skip to content
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

fix: isPostsPage on content type #3048

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 2 additions & 10 deletions src/Model/PostType.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,8 @@ protected function init() {
},
// If the homepage settings are to set to
'isPostsPage' => function () {
if (
'post' === $this->name &&
(
'posts' === get_option( 'show_on_front', 'posts' ) ||
empty( (int) get_option( 'page_for_posts', 0 ) ) )
) {
return true;
}

return false;
// the "post" ContentType is always represented as isPostsPage
return 'post' === $this->name;
Copy link

Choose a reason for hiding this comment

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

Avoid too many return statements within this method.

},
'isFrontPage' => function () {
if (
Expand Down
14 changes: 14 additions & 0 deletions src/Type/InterfaceType/UniformResourceIdentifiable.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ public static function register_type( TypeRegistry $type_registry ) {
return $node instanceof Term;
},
],
'isFrontPage' => [
'type' => [ 'non_null' => 'Bool' ],
'description' => __( 'Whether the node represents the front page.', 'wp-graphql' ),
'resolve' => function( $node, $args, $context, $info ) {
return isset( $node->isFrontPage ) && (bool) $node->isFrontPage;
},
],
'isPostsPage' => [
'type' => [ 'non_null' => 'Bool' ],
'description' => __( 'Whether the node represents the blog page.', 'wp-graphql' ),
'resolve' => function( $node, $args, $context, $info ) {
return isset( $node->isPostsPage ) && (bool) $node->isPostsPage;
},
],
],
'resolveType' => static function ( $node ) use ( $type_registry ) {
switch ( true ) {
Expand Down
3 changes: 3 additions & 0 deletions tests/wpunit/NodeByUriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public function getQuery(): string {
databaseId
}
uri
isPostsPage
isFrontPage
}
}
';
Expand Down Expand Up @@ -1896,6 +1898,7 @@ public function testPageForPostsByUri() {

$this->assertArrayNotHasKey( 'errors', $actual );
$this->assertSame( 'ContentType', $actual['data']['nodeByUri']['__typename'] );
$this->assertTrue( $actual['data']['nodeByUri']['isPostsPage'] );

delete_option( 'page_for_posts' );

Expand Down