-
Notifications
You must be signed in to change notification settings - Fork 385
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
Support late-defined slugs for paired URL structures and Reader themes #6125
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #6125 +/- ##
=============================================
+ Coverage 75.08% 75.11% +0.02%
- Complexity 5846 5847 +1
=============================================
Files 234 234
Lines 17663 17667 +4
=============================================
+ Hits 13263 13271 +8
+ Misses 4400 4396 -4
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Plugin builds for 3549c0a are ready 🛎️!
|
To test this, I first installed 2.0.11 and emptied out the I activated a plugin which did this: add_action( 'setup_theme', function () {
define( 'AMP_QUERY_VAR', 'lite' );
} ); And I flushed my rewrite rules. Then I went through the onboarding wizard and saw the notice I could only select the legacy theme: The Then I switched to the build for this PR via the QA Tester plugin. Upon doing so I was able to confirm:
16c16
< 'version' => '2.0.11',
---
> 'version' => '2.1.0-beta2-20210427T201055Z-8d1cbcc',
17a18
> 'paired_url_structure' => 'legacy_reader',
22a24,25
> 'primary_theme_support' => NULL,
> 'late_defined_slug' => 'lite',
|
There are two cases that are not currently accounted for:
|
I've added 61c7c29 as a prototype for how to address these cases. It checks to see if the option storing the late-defined slug is different than the current late-defined slug. If so, it schedules an immediate event to update the option. It's scheduling an event rather than updating the option right then and there in order to frontend writes which we worked to avoid in #3284. However, it's true that scheduling a cron event does do a frontend write. So maybe this is no better. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nitpick.
That is only true for sites which use out-of-the-box WP scheduling. Most high traffic sites will use a real cron process instead, which will run the DB update in a proper, separate background process. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from the suggestion @schlessera raised, this looks good 👍.
Co-authored-by: Alain Schlesser <[email protected]>
@schlessera But what about actually scheduling the task? Calling |
@schlessera so this means there will be a frontend write to the |
If I understand correctly, this would only happen the first time after a slug change AND the slug change is done with bad timing, correct? |
It would happen if you, for example, had a theme that defined the |
I have a compromise. It seems we need to do a frontend DB write, either by scheduling a task to update the option or updating the AMP options directly. Nevertheless, having a late-defined AMP slug is not the ideal. So what we can do is add a notice that encourages the site owner to move slug to be defined in a plugin at top-level (before |
That sounds like a good compromise. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, LGTM .
QA Passed Given a plugin with the following filter: add_action( 'setup_theme', function () {
define( 'AMP_QUERY_VAR', 'lite' );
} );
|
In that case, shouldn't they just be pointed to our settings screen and be able to set the slug there? |
We don't provide a UI to change the slug, at least not yet. This is not something that 80% of users require so I don't think a UI is warranted. I can only recall a few sites that have customized the slug. |
Summary
I just found a problem related to defining the AMP query var late. While at first this was only a problem for Reader themes, I realize it also (naturally) applies to when you're using paired URL structures, especially the legacy Reader or path suffix which involve
/amp/
. So if you have a plugin that does this:And you have the paired URL structure set to "Path suffix". Going to
/2020/01/07/hello-world/lite/
results in a 404. This is because the routing logic in thePairedRouting
service gets run way earlier atplugins_loaded
, so as far as it knows the the path suffix is/amp/
at that point since the logic insetup_theme
hasn't run yet.This circles back to the discussion we had 5 days ago, captured in Joshua's notes: #5859 (comment)
The way to fix this and also to allow any Reader theme even when late-defined slug is used, is to store the late-defined slug in an option. This would cache it to allow it to be used at any point in the WP page lifecycle.
This PR implements this idea which was first explored in #6042 for caching the primary theme's support features in options so that they are available when a Reader theme is selected.
Site Health Check
When the AMP slug (query var) is customized, a new Site Health check is added which tells the user if it was defined early (good) or late (bad). If late, it is recommended that they change the definition to be earlier by putting in a plugin:
If the user has not customized the AMP slug or if the site is in Standard mode (where the AMP slug is irrelevant), then the test is omitted entirely.
This information is also now included in Site Health Info:
Rewrite Endpoint Removed
In 3420914 an
add_rewrite_endpoint()
call was removed which should have been removed as part of #5558. Paired URL Structures do not use rewrite endpoints now, so there is no need to add a rewrite endpoint nor to flush them when settings change.Checklist