wpengine / faustjs

Faust.js™ - The Headless WordPress Framework
https://faustjs.org
Other
1.44k stars 134 forks source link

Adding a filter for optional change of public redirect status codes #1985

Open infn8 opened 1 week ago

infn8 commented 1 week ago

Adding support for users to change the redirect status code from a 302 to another code of their choice, likely 301.

Tasks

Description

Added new filter faustwp_public_redirect_status_code, allowing WordPress plugins and themes to choose the HTTP status code to use when generating redirects when the enable public route redirects setting is active.

Related Issue(s):

None

Testing

I added this locally and ensured that the redirects were still 302 status codes. I then added this in my theme's functions.php file to test it

add_filter('faustwp_public_redirect_status_code', function ($status_code) {
    return 301;
}, 10, 1);

Then I tried calling the exact same URL which resulted in a 301 status code with no change to other headers including the x-redirect-by: WP Engine Headless plugin header

Screenshots

none

Documentation Changes

There is nowhere in the repo docs that cover this functionality but there is the following on the live site:

https://faustjs.org/reference/faust-wordpress-plugin-filters

So I am writing here markdown that will get you close, if not all the way to an update for that page which i do not know how to edit:

faustwp_exclude_from_public_redirect: Choose the HTTP status code to use when generating redirects when the enable public route redirects setting is active.

Parameter: $status_code (int): HTTP Status code to use on redirects. Default: 302

Example Usage

// Make the homepage redirect 301 while all others remain unchanged
add_filter('faustwp_public_redirect_status_code', function ($status_code) {
  if(is_front_page()){
    return 301;
  }
  return $status_code;
}, 10, 1);

Dependant PRs

none

headless-platform-by-wp-engine[bot] commented 1 week ago

Currently, we do not support the creation of preview deployments based on changes coming from forked repositories. Learn more about preview environments in our documentation.

changeset-bot[bot] commented 1 week ago

🦋 Changeset detected

Latest commit: dc757777b657d70bdb1e6b44565e8d41b0838536

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ------------------------- | ----- | | @faustwp/wordpress-plugin | Minor |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

infn8 commented 1 week ago

🤞 I hope I made that changeset properly. First one!!!