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

Add back-compat to old WP versions for new v2.2 features #6773

Merged
merged 37 commits into from
Dec 14, 2021

Conversation

westonruter
Copy link
Member

@westonruter westonruter commented Dec 8, 2021

Test new (and existing) plugin features in WordPress 4.9 and above. Add todos for fixing below:

  • Limit AMP integration on Add Plugins screen to WordPress 5.6+.
  • Limit AMP integration on Add Themes screen to WordPress 5.6+.
  • Limit plugin activation site scan to WordPress 5.6+.
  • Ensure Support screen works in 5.2+ and that it is hidden in older versions.
  • Add status=active parameter to /wp/v2/themes REST API calls for compat with WP<5.7. (See https://core.trac.wordpress.org/ticket/50152)
  • Limit the _fields requested form the plugins and themes endpoints to be just those which are needed.
  • Fix Settings screen loading in WP 4.9+.
  • Fix Onboarding Wizard loading in WP 4.9+.

Fixes #6775.
Closes #6771.

@westonruter westonruter added the P0 High priority label Dec 8, 2021
@westonruter westonruter added this to the v2.2 milestone Dec 8, 2021
@westonruter
Copy link
Member Author

@delawski Is there a need to include non-active themes in the response? I suppose so since it seems that a parent theme is not included in the list if you add ?status=active. If so, 949eeb3 may need to be reverted and Site Scanning be made a WP 5.7+ required feature.

@westonruter
Copy link
Member Author

It may be worthwhile to limit the queried themes and plugins to just those which are active, as if there are many themes and plugins installed will they all be included in the response? Actually, that brings to mind: what if there are hundreds of installed plugins and hundreds of installed themes? It seems that there is no pagination for either of the themes or plugins endpoints, so there should be a _fields parameter added to limit the fields to just the ones we need. In particular, I believe we should exclude fields like description.

On WordPress 5.4 and older, the themes and plugins REST endpoints are not available. We use them in Site Scan for providing a source name, version, and author instead of a bare slug. Since this information is supplementary, we can fail silently if the endpoints are not available.
@delawski
Copy link
Collaborator

delawski commented Dec 8, 2021

I've pushed a few commits that should fix the Site Scan on AMP Settings screen and in the Onboarding Wizard.

The scanner works now even though the/wp/v2/plugins and /wp/v2/themes REST paths are missing. We need the themes and plugins data just to provide additional information to the user. Even without it, we still have a slug which should be useful to a user:

Screenshot 2021-12-08 at 11 18 27

Based on this assumption, I made the themes and plugins requests to fail silently in f57f25c.

Also, in 148d397 I've limited the fields we're requesting for themes and plugins. I haven't touched the pagination issue, though.

Lastly, with 3f3cb57 the Onboarding Wizard should work fine on WP 4.9.

@westonruter westonruter marked this pull request as ready for review December 8, 2021 16:54
@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2021

Plugin builds for ff7e7b7 are ready 🛎️!

@codecov
Copy link

codecov bot commented Dec 8, 2021

Codecov Report

Merging #6773 (bec8cbe) into develop (4cd08b2) will decrease coverage by 0.81%.
The diff coverage is 93.93%.

❗ Current head bec8cbe differs from pull request most recent head cff0d8f. Consider uploading reports for the commit cff0d8f to get more accurate results
Impacted file tree graph

@@              Coverage Diff              @@
##             develop    #6773      +/-   ##
=============================================
- Coverage      78.29%   77.47%   -0.82%     
- Complexity      6693     6700       +7     
=============================================
  Files            203      268      +65     
  Lines          20150    21356    +1206     
=============================================
+ Hits           15776    16546     +770     
- Misses          4374     4810     +436     
Flag Coverage Δ
javascript 63.47% <ø> (?)
php 78.29% <93.93%> (+<0.01%) ⬆️
unit 78.29% <93.93%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/Admin/AmpPlugins.php 99.05% <50.00%> (-0.95%) ⬇️
src/Admin/AmpThemes.php 98.86% <50.00%> (-1.14%) ⬇️
...cludes/validation/class-amp-validation-manager.php 83.21% <100.00%> (+0.03%) ⬆️
src/Admin/OnboardingWizardSubmenuPage.php 91.12% <100.00%> (+0.45%) ⬆️
src/Admin/OptionsMenu.php 94.69% <100.00%> (+0.25%) ⬆️
src/Admin/PluginActivationSiteScan.php 100.00% <100.00%> (ø)
src/Admin/SupportLink.php 96.36% <100.00%> (+0.06%) ⬆️
src/Admin/SupportScreen.php 98.83% <100.00%> (+0.04%) ⬆️
includes/sanitizers/class-amp-style-sanitizer.php 87.45% <0.00%> (-0.20%) ⬇️
assets/src/utils/use-async-error.js 0.00% <0.00%> (ø)
... and 64 more

@westonruter
Copy link
Member Author

When testing Twenty Seventeen in WP 4.9, I was surprised to see a script error coming from comment-reply.min.js:

image

This is due to the id attribute being added to scripts starting with WP 5.5. So this is fixed with cff0d8f.

@westonruter
Copy link
Member Author

westonruter commented Dec 8, 2021

In Wordpress 5.2.13 I see something weird where the REST API call to obtain the settings data is:

https://wordpress-stable.lndo.site/amp/v1/options?_locale=user 

Note there is no /wp-json/ in the URL. This is resulting in the error screen being shown:

image

This is true of all the REST API URLs:

image

This error doesn't occur in WP 5.3.10, so there's something uniquely broken about WP 5.2.x.

@westonruter
Copy link
Member Author

@delawski I think this was actually fixed by #6776 since without that chance I get errors in those 3 scripts:

image

If I revert your change in 3f3cb57 after having merged develop including #6776, I am no longer getting any errors and the Onboarding Wizard loads successfully in 4.9. Those three scripts are being included on the page.

// shown, and its the user interface which is particularly problematic on older versions of WP due to the
// JavaScript dependencies.
if ( ! $this->dependency_support->has_support() ) {
return false; // @codeCoverageIgnore
Copy link
Collaborator

@delawski delawski Dec 13, 2021

Choose a reason for hiding this comment

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

It seems that because of this check, it's impossible to toggle developer tools on WP 4.9-5.5. Is it intended?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should just prevent users access to validation screens in WP<5.6.

@westonruter Actually, in light of #6775 (comment), do you think we should disable developer tools on WP<5.6, too? If yes, then we should hide the toggle here and also remove one of the steps in the Onboarding Wizard.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good question. Developer tools access is broken down into two aspects:

  • Capability check: the users should never have access to DevTools (or the validation nonce)
  • Preference check: validation data should not be presented to the user.

In the case of a user being on an old WP install, the latter check is more appropriate because what we're wanting to do is to prevent displaying the validation UI to the user since it won't work properly. Technically such a user could still manually go to the validation screens if they know the URLs, but that is OK since they still have the capability and we aren't blocking their access.

So I think we can keep the step in the Onboarding Wizard. It's just we won't link to the Validated URLs screen.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure if we're on the same page. Here's a recording of what I meant (notice that the response's payload always returns amp_dev_tools_enabled: false meaning the "Enable Developer Tools" toggle is useless):

Screen.Recording.2021-12-13.at.09.30.17.PM.mp4

The same applies to the Technical Background step of the Wizard.

Screenshot 2021-12-13 at 21 33 28

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh! I see what you're referring to.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've addressed this in ff7e7b7 by hiding the toggle which appears on the settings screen as well as the toggle that appears on the user profile screen.

Copy link
Member Author

Choose a reason for hiding this comment

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

also remove one of the steps in the Onboarding Wizard.

@delawski Oh, I didn't do this part. If you would open a PR to address this, I'd appreciate it. It's consider this not to be a blocker for 2.2, since it only affects WP<5.6 (which granted is about a third of all installs).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sure! This one seems to be easy: #6789.

@westonruter westonruter requested a review from delawski December 13, 2021 17:20
@dhaval-parekh dhaval-parekh self-requested a review December 13, 2021 19:33
@dhaval-parekh
Copy link
Collaborator

dhaval-parekh commented Dec 13, 2021

QA Passed.

✅ AMP Plugin/Theme is only highlighted in 5.6 and the newer versions of WordPress.

✅ Site scanning is disabled after plugin activation in the WordPress version prior to 5.6

✅ Support page is only available in 5.2 and the newer versions of WordPress.

✅ Did not find any issue on the "AMP Setting" screen and "Onboarding Wizard" in WordPress 4.9

Copy link
Collaborator

@dhaval-parekh dhaval-parekh left a comment

Choose a reason for hiding this comment

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

Changes in PR looks good to me.

@westonruter westonruter merged commit 27a2104 into develop Dec 14, 2021
@westonruter westonruter deleted the add/wp-back-compat branch December 14, 2021 00:16
@westonruter westonruter added the Changelogged Whether the issue/PR has been added to release notes. label Dec 15, 2021
@delawski
Copy link
Collaborator

QA Passed

✅ DevTools toggle is not rendered on WP<5.6

WP 4.9 WP 5.5 WP 5.6
Screenshot 2021-12-15 at 11 32 42 Screenshot 2021-12-15 at 11 34 21 Screenshot 2021-12-15 at 11 36 22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelogged Whether the issue/PR has been added to release notes. P0 High priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enqueued scripts are not printed on validation screens in WP 4.9
4 participants