-
Notifications
You must be signed in to change notification settings - Fork 798
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
Widget visibility: supporting load conditions for legacy widgets in gutenberg widgets screen #20255
Conversation
Caution: This PR has changes that must be merged to WordPress.com |
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available. Once your PR is ready for review, check one last time that all required checks (other than "Required review") appearing at the bottom of this PR are passing or skipped. Jetpack plugin:
|
Current status:
I think the best way forward is to change the form input names inside the plugin and change |
projects/plugins/jetpack/modules/widget-visibility/widget-conditions.php
Outdated
Show resolved
Hide resolved
projects/plugins/jetpack/modules/widget-visibility/widget-conditions.php
Outdated
Show resolved
Hide resolved
projects/plugins/jetpack/modules/widget-visibility/widget-conditions.php
Show resolved
Hide resolved
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.
Tested this on WP 5.8 and works as expected both in widgets.php
and in customizer.
I have left some comments where I think we can improve the performance, let's discuss them.
projects/plugins/jetpack/modules/widget-visibility/widget-conditions.php
Outdated
Show resolved
Hide resolved
projects/plugins/jetpack/modules/widget-visibility/widget-conditions/widget-conditions.js
Show resolved
Hide resolved
projects/plugins/jetpack/modules/widget-visibility/widget-conditions/widget-conditions.js
Outdated
Show resolved
Hide resolved
projects/plugins/jetpack/modules/widget-visibility/widget-conditions/widget-conditions.js
Outdated
Show resolved
Hide resolved
projects/plugins/jetpack/modules/widget-visibility/widget-conditions.php
Outdated
Show resolved
Hide resolved
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.
Thanks for refactoring this @dsas! I can confirm that code now runs only when is needed 🎉 !
I tested this on:
- WP 5.8 - Local Jetpack
- WP 5.7 - Simple Site by applying the patch in my Sandbox
- WP 5.7 - Atomic Site by using https://jetpack.com/download-jetpack-beta/ to switch to this branch
It works as expected in all instances!
Let's get the crew in the review process.
projects/plugins/jetpack/modules/widget-visibility/widget-conditions.php
Outdated
Show resolved
Hide resolved
projects/plugins/jetpack/modules/widget-visibility/widget-conditions.php
Outdated
Show resolved
Hide resolved
projects/plugins/jetpack/modules/widget-visibility/widget-conditions.php
Outdated
Show resolved
Hide resolved
// Don't filter widgets when editing them - otherwise they could get filtered out and become impossible to edit. | ||
( false === strpos( wp_get_raw_referer(), '/wp-admin/widgets.php' ) ) |
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.
I may be missing something here, but wouldn't that mean that if I click on the site title in the admin bar to access my home page after editing widgets, the widgets would not be filtered then?
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.
This is a very good point :(
The problem I have is that I can't find a way to tell the difference between the API being used to fetch the widgets to display, and the API being used to fetch the list of widgets to edit - it's the same end point - /wp-json/wp/v2/sidebars.
Unless there's something I've missed, the other option is to never filter the list at all.
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.
That's a good point. I don't have a great solution here either :\
@cpapazoglou Have you had the chance to look at this?
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.
At first I thought this was a problem with conditions like "Hide if User is logged in" but trying to reproduce it now and the widget still displays after saving them while being in http://localhost/wp-admin/widgets.php
.
@dsas is there a chance that this is resolved and we don't need ( false === strpos( wp_get_raw_referer(), '/wp-admin/widgets.php' ) )
? Otherwise can you provide the exact steps to reproduce the they could get filtered out and become impossible to edit.
?
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.
Yes, it definitely still happens, here are the exact steps, sorry for not providing them earlier:
- Add legacy widget using /wp-admin/widgets.php
- Set visibility to "Show if User is logged out"
- Press update to save them
- Reload the page
- See that the newly added widget does not appear.
Screen recording here if that helps: https://d.pr/v/lJVdjv
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.
@jeherve We have solved this by changing the referer check to only be used if using the API.
This means if the API is used it will filter out widgets, unless it's called from the widgets admin page. This means they can still be edited there.
The customizer is unaffected - it doesn't use the same sidebars API anyway.
The solution is perhaps a little bit of a hack, other alternatives we thought about were:
- Never filter out widgets from the API i.e. eliminate the referer check. It didn't seem completely correct and might surprise people. Particularly if someone was using this API for something other than widget editing.
- Get a change upstream so that when the API is called it explains why it's calling e.g. by adding a context=editing request var, we can then look for that request var and choose not to run the filters. This would take some time to coordinate.
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.
Something to note is security. I was worried about depending upon the referer to decide whether or not to filter out conditions, as that's totally in control of the client. The sidebar endpoint is only available to users with the edit_theme_options cap though, so it's ok 👍
Previously $_POST['action'] was used to avoid registering hooks in one case - the heartbeat API. This has been changed from a block list to an allow list, to minimise registering hooks when unnecessary.
Previously registration of the front-end hooks was not done in the referer was the widgets.php admin page. This prevented the API from running the filters which made filtered out widgets uneditable. This also had the effect of running the filters if you clicked from the widgets page to e.g. the homepage, which would look confusing to users. This has been solved by changing the check so that filters aren't ran if on the REST API AND the referer is the widgets.php admin page.
7a63701
to
6595b8e
Compare
Presumably we have already addressed these CSS issues. Can you let us know:
|
Ah looks like this occurs only in Firefox (v 90.0) running on my macOS Big Sur 11.4. Works fine for me in Chrome and Safari. Tested using the Jurassic Ninja live site. |
@sdixon194 I can reproduce the select issue (line-height?) in firefox with other selects in other legacy widgets too, even with jetpack plugin disabled. If you deactivate the jetpack plugin, and then add a navigation menu widget, you should see the same thing. I'll try to find out where this is coming from, but I don't think it's due to this issue and shouldn't block it. |
Nice sleuthing! Agreed it's non-blocking! 👍 |
…cy widgets in gutenberg widgets screen (#20255) Co-authored-by: Harris Papazolgou <[email protected]> Co-authored-by: cpap <[email protected]>
Great news! One last step: head over to your WordPress.com diff, D63633-code, and commit it. Thank you! |
Cherry picked to release branch in 4b3956c |
Thanks @sdixon194. I checked in the dotorg slack whether this was known and they've now filed WordPress/gutenberg#33431 |
Nice, thanks for checking! |
…utenberg widgets screen (#20255) Co-authored-by: Harris Papazolgou <[email protected]> Co-authored-by: cpap <[email protected]>
Deployed r228664-wpcom |
This seems to be generating some PHP Notices I'm seeing in an error log --
as the change is doing
without ever checking first to make sure May be worth revising to check if it's not |
thanks @georgestephanis, might be worth opening up a separate issue with reproduction steps - I can't reproduce it here and want to make sure I've caught all occurrences. |
@dsas I've not attempted to duplicate, but my guess is there was a cli script or something being triggered via cli (wp-cron.php maybe) that could lead to the request method not being set. |
Lets the widget visibility conditions run using the new gutenberg based
widgets screen.
Fixes #20057
Changes proposed in this Pull Request:
Jetpack product discussion
Does this pull request change what data or activity we track or use?
No.
Testing instructions:
Gutenberg widget editor
This requires testing on WordPress 5.8
Widgets admin
Repeat again, this time set-up two widgets together before pressing update.
Customizer
As above but go to 'Appearance > Customizer' first and use the 'Publish' button rather than 'Update'
Classic widget editor