-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
User-related REST API calls to /wp/v2/users/me?context=edit
in Preferences Persistence even if user is not logged in
#60325
Comments
@therealgilles Thanks for reporting this. Please could you provide some more detailed reproduction steps? I tried to reproduce the error you're seeing but couldn't. The preferences API is fairly limited at the moment to the block editor (AFAIK) and isn't used on any WP page. The only way I found to reproduce it was to log out in a separate tab, and try changing preferences in the block editor, which resulted in a It could be that you have a plugin active that uses the preferences API, and is making requests on all WP Pages, so you could try testing with plugins disabled (on a staging site?). |
UPDATE: Let me double-check on my side... Hi @talldan, thank you for the reply. Here is the code where the script is loaded: I don't see any condition based on whether we're on a page or on the Then the script is executed here: Again, there is no check as to whether it is the Am I missing something? PS: If I am correct, I see the user ID is passed to the script, so it should be a pretty easy fix to prevent the API calls. |
In the code you linked to, that script is specifically loaded only after the Still, the script can be loaded, but it shouldn't (and in my testing I didn't see it) trigger an HTTP request like you're describing. gutenberg/packages/preferences/src/store/reducer.js Lines 48 to 52 in a51a67d
The code that makes the HTTP request you describe is instead gutenberg/packages/preferences/src/store/reducer.js Lines 54 to 57 in a51a67d
It calls through to here where the api fetch call is made (debounced to avoid to many http requests): gutenberg/packages/preferences-persistence/src/create/index.js Lines 71 to 106 in 5e8a210
Hopefully that makes it clearer how it's supposed to work. I'm not sure what's happening in your environment, but it could be that a plugin is loading Let me know if you spot any issues with what I mention above. |
You must be right. Let me try to find the faulty plugin. |
Here is a stack trace. It looks like the call to => require(["\/...\/public_html\/wp-blog-header.php"]) / /.../public_html/index.php, line 17
=> require_once(["\/...\/public_html\/wp-load.php"]) / /.../public_html/wp-blog-header.php, line 13
=> require_once(["\/...\/public_html\/wp-config.php"]) / /.../public_html/wp-load.php, line 50
=> require_once(["\/...\/public_html\/wp-settings.php"]) / /.../public_html/wp-config.php, line 142
=> do_action(["init"]) / /.../public_html/wp-settings.php, line 695
=> do_action([[""]]) / /.../public_html/wp-includes/plugin.php, line 517
=> apply_filters([null,[""]]) / /.../public_html/wp-includes/class-wp-hook.php, line 348
=> register_in_wp / /.../public_html/wp-includes/class-wp-hook.php, line 322
=> wp_script_is(["tribe-common","registered"]) / /.../public_html/wp-content/plugins/the-events-calendar/common/src/Tribe/Assets.php, line 264
=> wp_scripts / /.../public_html/wp-includes/functions.wp-scripts.php, line 425
=> __construct / /.../public_html/wp-includes/functions.wp-scripts.php, line 24
=> init / /.../public_html/wp-includes/class-wp-scripts.php, line 149
=> do_action_ref_array(["wp_default_scripts",[{"registered":{"utils":{"handle":"utils","src":"\/wp-includes\/js\/utils.min.js","deps":[],"ver":false,"args":null,"extra":{"data":"var userSettings = {\"url\":\"\\\/\",\"uid\":...) / /.../public_html/wp-includes/class-wp-scripts.php, line 166
=> do_action([[{"registered":{"utils":{"handle":"utils","src":"\/wp-includes\/js\/utils.min.js","deps":[],"ver":false,"args":null,"extra":{"data":"var userSettings = {\"url\":\"\\\/\",\"uid\":\"0\",\"time\":\"1712...) / /.../public_html/wp-includes/plugin.php, line 565
=> apply_filters([null,[{"registered":{"utils":{"handle":"utils","src":"\/wp-includes\/js\/utils.min.js","deps":[],"ver":false,"args":null,"extra":{"data":"var userSettings = {\"url\":\"\\\/\",\"uid\":\"0\",\"time\":\...) / /.../public_html/wp-includes/class-wp-hook.php, line 348
wp_default_packages([{"registered":{"utils":{"handle":"utils","src":"\/wp-includes\/js\/utils.min.js","deps":[],"ver":false,"args":null,"extra":{"data":"var userSettings = {\"url\":\"\\\/\",\"uid\":\"0\",\"time\":\"17121...) / /.../public_html/wp-includes/class-wp-hook.php, line 324 |
I tracked it down to the Updraft Central plugin. Closing. |
Description
The code below makes REST API calls to
/wp/v2/users/me?context=edit
even when the user is not logged in.gutenberg/packages/preferences-persistence/src/create/index.js
Line 44 in 5e8a210
gutenberg/packages/preferences-persistence/src/create/index.js
Line 91 in 5e8a210
On my site, this results in a 401 (unauthorized) response, maybe because of my REST API security settings. I deem this call unnecessary as the code should have a way to skip them if the user is not logged in.
Should this script even be loaded if a user is not logged in?
Step-by-step reproduction instructions
Load any WP page. Wait for the REST API to be triggered.
Screenshots, screen recording, code snippet
No response
Environment info
WordPress 6.4.3
My theme is not using Gutenberg blocks.
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
No
The text was updated successfully, but these errors were encountered: