ashhitch / wp-graphql-yoast-seo

This is an extension to the WPGraphQL plugin for Yoast SEO
GNU General Public License v3.0
225 stars 48 forks source link

Cannot redeclare `get_post_type_graphql_fields()` previously declared #161

Closed renatonascalves closed 1 year ago

renatonascalves commented 1 year ago

I noticed this bug while adding unit tests in a plugin.

PHP Fatal error:  Cannot redeclare get_post_type_graphql_fields() (previously declared in /var/www/project/wp-content/plugins/add-wpgraphql-seo/wp-graphql-yoast-seo.php:748) in /var/www/project/wp-content/plugins/add-wpgraphql-seo/wp-graphql-yoast-seo.php on line 748

Fatal error: Cannot redeclare get_post_type_graphql_fields() (previously declared in /var/www/project/wp-content/plugins/add-wpgraphql-seo/wp-graphql-yoast-seo.php:748) in /var/www/project/wp-content/plugins/add-wpgraphql-seo/wp-graphql-yoast-seo.php on line 748

The issue seems to be because this function is being instantiated inside the graphql_register_types hook action which can be run multiple times.

https://github.com/ashhitch/wp-graphql-yoast-seo/blob/278d751c765dba031fdcbeec1ed0d425a16486be/wp-graphql-yoast-seo.php#L748