From 56d7104aca5c524da3fe473075f4c5872e032863 Mon Sep 17 00:00:00 2001 From: Joe Fusco Date: Mon, 2 Nov 2026 16:49:43 -0500 Subject: [PATCH 1/4] fix(faustwp): stop the templates field from changing other nodes' content templates_resolver() removed prepend_attachment from the_content when it found an attachment template, copied from WordPress's template-loader.php. In a GraphQL request that filter was never restored, so a media item's content depended on whether templates had been selected earlier in the query. --- plugins/faustwp/includes/graphql/callbacks.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/plugins/faustwp/includes/graphql/callbacks.php b/plugins/faustwp/includes/graphql/callbacks.php index a513962f6..74e506855 100644 --- a/plugins/faustwp/includes/graphql/callbacks.php +++ b/plugins/faustwp/includes/graphql/callbacks.php @@ -199,10 +199,6 @@ function templates_resolver( $root, $args, AppContext $context, ResolveInfo $inf } if ( $template ) { - if ( 'is_attachment' === $tag ) { - remove_filter( 'the_content', 'prepend_attachment' ); - } - break; } } From 582379069e9944a5ff51df7cfa87381f51cd1885 Mon Sep 17 00:00:00 2001 From: Joe Fusco Date: Mon, 2 Nov 2026 16:57:39 -0500 Subject: [PATCH 2/4] test(faustwp): cover the templates field leaving the_content alone --- .../integration/GraphQLCallbacksTests.php | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/plugins/faustwp/tests/integration/GraphQLCallbacksTests.php b/plugins/faustwp/tests/integration/GraphQLCallbacksTests.php index 8e4e57fcc..d01ebfba1 100644 --- a/plugins/faustwp/tests/integration/GraphQLCallbacksTests.php +++ b/plugins/faustwp/tests/integration/GraphQLCallbacksTests.php @@ -16,6 +16,7 @@ use function WPE\FaustWP\GraphQL\{ filter_introspection, + templates_resolver, }; class GraphQLCallbacksTests extends \WP_UnitTestCase { @@ -197,6 +198,33 @@ public function test_filter_introspection_returns_on_when_faust_secret_key_is_pr remove_filter( 'faustwp_get_setting', [ $this, 'filter_secret_key' ] ); } + /** + * Tests templates_resolver() leaves the_content alone when it finds an attachment template. + */ + public function test_templates_resolver_keeps_prepend_attachment_for_attachments(): void { + $attachment_id = self::factory()->attachment->create_object( + 'image.jpg', + 0, + [ + 'post_mime_type' => 'image/jpeg', + 'post_status' => 'inherit', + ] + ); + $this->go_to( get_attachment_link( $attachment_id ) ); + + $attachment_template = static function () { + return __FILE__; + }; + add_filter( 'attachment_template', $attachment_template ); + + $templates = templates_resolver( [], [], new \WPGraphQL\AppContext(), $this->createMock( \GraphQL\Type\Definition\ResolveInfo::class ) ); + + remove_filter( 'attachment_template', $attachment_template ); + + self::assertContains( 'attachment', $templates ); + self::assertSame( 10, has_filter( 'the_content', 'prepend_attachment' ) ); + } + /** * Filters the secret key value for testing. * From 8627dbed2bda5bedd8f387aaff3da049ce14c906 Mon Sep 17 00:00:00 2001 From: Joe Fusco Date: Mon, 2 Nov 2026 16:58:01 -0500 Subject: [PATCH 3/4] test(faustwp): explain the attachment template stub and drop its manual cleanup --- .../tests/integration/GraphQLCallbacksTests.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/plugins/faustwp/tests/integration/GraphQLCallbacksTests.php b/plugins/faustwp/tests/integration/GraphQLCallbacksTests.php index d01ebfba1..5bc4638f8 100644 --- a/plugins/faustwp/tests/integration/GraphQLCallbacksTests.php +++ b/plugins/faustwp/tests/integration/GraphQLCallbacksTests.php @@ -212,15 +212,16 @@ public function test_templates_resolver_keeps_prepend_attachment_for_attachments ); $this->go_to( get_attachment_link( $attachment_id ) ); - $attachment_template = static function () { - return __FILE__; - }; - add_filter( 'attachment_template', $attachment_template ); + // The test theme has no attachment template, so pretend it does. WP_UnitTestCase removes the filter afterwards. + add_filter( + 'attachment_template', + static function () { + return __FILE__; + } + ); $templates = templates_resolver( [], [], new \WPGraphQL\AppContext(), $this->createMock( \GraphQL\Type\Definition\ResolveInfo::class ) ); - remove_filter( 'attachment_template', $attachment_template ); - self::assertContains( 'attachment', $templates ); self::assertSame( 10, has_filter( 'the_content', 'prepend_attachment' ) ); } From 52b0c238ee6bbc09beec9db7298b8bac8ac5f577 Mon Sep 17 00:00:00 2001 From: Joe Fusco Date: Tue, 3 Nov 2026 05:32:40 -0500 Subject: [PATCH 4/4] test(faustwp): trim the attachment template stub comment --- plugins/faustwp/tests/integration/GraphQLCallbacksTests.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/faustwp/tests/integration/GraphQLCallbacksTests.php b/plugins/faustwp/tests/integration/GraphQLCallbacksTests.php index 5bc4638f8..72f90b6f5 100644 --- a/plugins/faustwp/tests/integration/GraphQLCallbacksTests.php +++ b/plugins/faustwp/tests/integration/GraphQLCallbacksTests.php @@ -212,7 +212,7 @@ public function test_templates_resolver_keeps_prepend_attachment_for_attachments ); $this->go_to( get_attachment_link( $attachment_id ) ); - // The test theme has no attachment template, so pretend it does. WP_UnitTestCase removes the filter afterwards. + // The test theme has no attachment template. add_filter( 'attachment_template', static function () {