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; } } diff --git a/plugins/faustwp/tests/integration/GraphQLCallbacksTests.php b/plugins/faustwp/tests/integration/GraphQLCallbacksTests.php index 8e4e57fcc..72f90b6f5 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,34 @@ 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 ) ); + + // The test theme has no attachment template. + add_filter( + 'attachment_template', + static function () { + return __FILE__; + } + ); + + $templates = templates_resolver( [], [], new \WPGraphQL\AppContext(), $this->createMock( \GraphQL\Type\Definition\ResolveInfo::class ) ); + + self::assertContains( 'attachment', $templates ); + self::assertSame( 10, has_filter( 'the_content', 'prepend_attachment' ) ); + } + /** * Filters the secret key value for testing. *