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

Fix Upgrade and Subsite Registration Redirects #13333

Merged
merged 5 commits into from
Aug 27, 2019
Merged

Conversation

mdawaffe
Copy link
Member

Fixes #5081.

Changes proposed in this Pull Request:

By default, Jetpack::activate_default_modules() redirects on error and queues an eventual redirect on success. This method is called in a few places where those redirects are not desired.

  • Never redirect during automatic upgrades. Automatic upgrades can be triggered by any visitor on init.
  • Never redirect during a Jetpack_Network->do_subsiteregister() call. Some of these calls are hooked to Core hooks, which can result in unexpected redirect behavior. Calls to Jetpack_Network->do_subsiteregister() should do their own error/success handling.
  • Default to not redirecting during non-wp-admin/ requests.
  • Default to not redirecting during REST, XML-RPC, AJAX, CRON, CLI requests.

Is this a new feature or does it add/remove features to an existing part of Jetpack?

No: Bug fix.

Testing instructions:

It's a huge pain :(

For do_subsiteregister(), create a custom CLI command as in #5081.

For upgrade requests, you have to:

  1. Deactivate the Protect module.
  2. Set the "First Introduced" header in the Protect module to "7.6.5".
  3. Open a new browser tab. In that browser tab, open the Network dev tools pane.
  4. wp jetpack options update version 7.6
  5. Quickly load the homepage (before some other request goes to your site).
  6. Inspect the network request for the homepage load.

Prior to this PR, you'll see a Location header. Depending on what else is going on on your site, the request will 200, so there won't actually be a redirect, though you can still see the header. (It may 301 is some circumstances, in which case, you will see the redirect.)

After this PR, there's no Location header and no redirect.

Proposed changelog entry for your changes:

  • Do not redirect during the automatic upgrades.

Don't redirect in `Jetpack::activate_default_modules()` when
auto-upgrading.
…ration.

`Jetpack::activate_default_modules()` redirects on failure, and queues a
redirect on success.

`Jetpack_Network->do_subsiteregister()` callers are expected to do their
own error and success handling, so there's no need to rely on
`Jetpack::activate_default_modules()`'s.

Fixes #5081.
This state change was gated behind the `$redirect` parameter. We want to
set the state regardless.
Only default to redirection in "normal" wp-admin/ requests.

Calling code can override to either force `$redirect = true` or
`$redirect = false`.
Don't show module state changes to users that can do something with the
information.
@mdawaffe mdawaffe added this to the 7.7 milestone Aug 27, 2019
@mdawaffe mdawaffe requested a review from a team August 27, 2019 01:15
@jetpackbot
Copy link
Collaborator

Warnings
⚠️

The PR is missing at least one [Status] label. Suggestions: [Status] In Progress, [Status] Needs Review

This is an automated check which relies on PULL_REQUEST_TEMPLATE. We encourage you to follow that template as it helps Jetpack maintainers do their job. If you think 'Testing instructions' or 'Proposed changelog entry' are not needed for your PR - please explain why you think so. Thanks for cooperation 🤖

Generated by 🚫 dangerJS against 383f9e4

@mdawaffe
Copy link
Member Author

I think we should get rid of Jetpack::activate_default_modules() success redirect entirely:

wp_safe_redirect( Jetpack::admin_url( 'page=jetpack' ) );

It was originally one of several failure redirects. As the code evolved, it (I think accidentally) got attached to the success state as well.

I think all calling code handles that redirect independently, so it serves no purpose.

I didn't want to do that in this PR, though, so close to 7.7.

Much of that module activation code needs cleaning up. It needs better ways to return errors: I don't think the Jetpack::state() code is used much anymore.

@mdawaffe mdawaffe added the [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. label Aug 27, 2019
@mdawaffe mdawaffe self-assigned this Aug 27, 2019
@jeherve jeherve added General [Pri] High [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Aug 27, 2019
Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to work, so I'll be merging this now. I'd love to get more eyes on this during the Beta though.

@iandunn @nickdaugherty @GaryJones Any chance you could test that change in your respective environments during the Beta?

Thank you!

@jeherve jeherve merged commit fdeb312 into master Aug 27, 2019
@jeherve jeherve deleted the fix/upgrade-redirects branch August 27, 2019 08:56
@matticbot matticbot added [Status] Needs Changelog and removed [Status] Ready to Merge Go ahead, you can push that green button! labels Aug 27, 2019
jeherve added a commit that referenced this pull request Aug 27, 2019
jeherve added a commit that referenced this pull request Aug 27, 2019
* 7.7 changelog: initial set of changes

* Changelog: add #13154

* Changelog: add #13134

* Changelog: add #12699 and many others

* Changelog: add #13127

* Changelog: add #13167

* Changelog: add #13225

* Changelog: add #13179

* Changelog: add #13173

* Changelog: add #13232

* Changelog: add #13137

* Changelog: add #13172

* Changelog: add #13182

* Changelog: add #13200

* Changelog: add #13244

* Changelog: add #13267

* Changelog: add #13204

* changelog: add #13205

* Changelog: add #13183

* Changelog: add #13278

* Changelog: add #13162

* Changelog: add #13268

* Changelog: add #13286

* Changelog: add #13273

* Changelog: add #12474

* Changelog: add #13085

* Changelog: add #13266

* Changelog: add #13306

* Changelog: add #13311

* Changelog: add #13302

* Changelog: add #13196

* Changelog: add #12733

* Changelog: add #13261

* Changelog: add #13322

* Changelog: add #13333

* Changelog: add #13335
@nickdaugherty
Copy link
Contributor

Apologies @jeherve - I missed your message. 7.8 has been deployed to VIP Go and I didn't notice any redirect issues this time. I believe it only happens when new default modules are activated and I'm not sure if 7.8 had any, but it was a smooth upgrade.

Thanks for working on this!

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

Successfully merging this pull request may close these issues.

Prevent redirect by Jetpack::activate_default_modules() in Jetpack_Network::do_subsiteregister()
5 participants