frontity / wp-plugins

» Frontity - Create amazing sites using WordPress & React

Home Page:https://frontity.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HeadTags cause failures on some REST API responses

luisherranz opened this issue · comments

Our HeadTags plugin is causing some routes to fail in the REST API. I've tried to debug it, but I don't seem to find the root of the problem.

These two posts explain the issue with more detail: https://community.frontity.org/tags/cors

We also saw this behavior in wp.frontity.org and I've been able to reproduce it locally.

Screen Shot 2020-01-24 at 18 14 00

We've found out that the problem happens because we are calling the template_redirect hook.

https://github.com/frontity/wp-plugins/blob/dev/plugins/frontity-headtags/includes/class-frontity-headtags.php#L142

I think I've solved it.

The template_redirect hook was calling the redirect_canonical callback (registered by WP in /wp-includes/default-filters.php). That callback accepts two arguments, being one of them a boolean value that indicates if redirect_canonical should redirect. By default, that value is true, and that's the reason why the REST API requests were redirected.

I've change the template_redirect call and the way redirect_canonical is registered and now it works.

Currently, I'm doing some testing to check that the integrations are working fine too.

Integrations are working as expected. 🙌

Awesome 👏 👏