Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: canary
Choose a base branch
from

Conversation

infn8
Copy link

@infn8 infn8 commented Nov 13, 2024

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

Tasks

  • I have signed a Contributor License Agreement (CLA) with WP Engine.
  • If a code change, I have written testing instructions that the whole team & outside contributors can understand.
  • I have written and included a comprehensive changeset to properly document the changes I've made.

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

adding support for users to change the redirect status code from a `302` to another code of their choice, likely `301`.
@infn8 infn8 requested a review from a team as a code owner November 13, 2024 18:25

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.

Copy link

changeset-bot bot commented Nov 13, 2024

🦋 Changeset detected

Latest commit: dc75777

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
Copy link
Author

infn8 commented Nov 13, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant