WordPress / wordpress-playground

Run WordPress in the browser via WebAssembly PHP
https://w.org/playground/
GNU General Public License v2.0
1.6k stars 239 forks source link

Users are not imported on importFile step #1158

Closed helgatheviking closed 5 months ago

helgatheviking commented 5 months ago

I have some users in my demo-content.xml for the importFile step to import.

When importing this file manually, the users are imported, however when activating the Simple User Listing plugin's preview, the users are not imported. (NB: By the time anyone reads this I'll probably have been tinkering with my blueprint.json and switched from import to CLI to just get it working)

But here are the errors I was seeing in the console that might be relvant?

[29-Mar-2024 15:56:29 UTC] PHP Deprecated: Function set_current_user is deprecated since version 3.0.0! Use wp_set_current_user() instead. in /wordpress/wp-includes/functions.php on line 140 [29-Mar-2024 15:56:29 UTC] PHP Notice: Object of class WP_User could not be converted to int in /wordpress/wp-includes/pluggable.php on line 2 config-d6770ff0.js:618:8515 [29-Mar-2024 15:56:29 UTC] PHP Deprecated: Function set_current_user is deprecated since version 3.0.0! Use wp_set_current_user() instead. in /wordpress/wp-includes/functions.php on line 140 [29-Mar-2024 15:56:29 UTC] PHP Notice: Object of class WP_User could not be converted to int in /wordpress/wp-includes/pluggable.php on line 2 [29-Mar-2024 15:56:30 UTC] PHP Deprecated: Hook http_api_transports is deprecated since version 6.4.0 with no alternative available. in /wordpress/wp-includes/functions.php on line 140

image

flexseth commented 5 months ago

@helgatheviking

however when activating the Simple User Listing plugin's preview, the users are not imported.

Troubleshooting a specific plugin is outside the scope of support here. I am guessing that this plugin is adding a "User 1" for some type of functionality. But I've never used this plugin...

Try installing a new version of the Playground, check your users. Install the plugin, check your users.

If the new user is created after the clean Playground install, it's not an issue with the Playground. That would be something that is happening as a result of the plugin.

Please let me know what you find out! Thank you for reporting this, I'm working on some best practices for troubleshooting and this is helpful to know what workflows Playground users are doing when finding potential bugs.

helgatheviking commented 5 months ago

I'm the author of that plugin so I am 99% confident it's not adding a stray user.

That said, I am trying to generate some users because I need them to display what my plugin does in the playground (a block that displays some users needs users to display)

I had an XMLfile that when imported manually generates users. When imported via the playground does not. That's what made me want to report it here as it's behaving differently in the playground import.

flexseth commented 5 months ago

I used your XML file to import users successfully into Playground

import-users_xml

After import

image
helgatheviking commented 5 months ago

Interesting. Is there a way I can quickly test this a few more times without have to SVN commit changes to the .org repo? Like can you launch a playground from any XML?

flexseth commented 5 months ago

Like can you launch a playground from any XML? https://playground.wordpress.net

You can test your import on a fresh Playground instance there.

helgatheviking commented 5 months ago

Did you import manually? I already confirmed that it works when manually imported via the WordPress admin/WordPress importer plugin.

It's not importing users when running from the blueprint.json's importFile step that is read when setting up as plugin preview in the playground.

So maybe instead I'm asking if you can set up a playground from any specific blueprint.json. at the moment, the only way I know how to test this is to keep making commits to my plugin's.org repo.

flexseth commented 5 months ago

@helgatheviking - I searched the wordpress-playground repo for the function set_current_user

It's only used in a couple of contexts

I'm thinking the deprecation errors you are seeing may be due to running an outdated version of wp-cli

Either way, I'm not seeing an error in this code that is Playground specific Being able to use the WordPress Importer functionality in Playground provides proof of this...

Going to leave this ticket open, but I'm out of ideas for suggestions as to what may be going wrong

adamziel commented 5 months ago

The deprecation notices are annoying and we should fix them, but they're just there normally and are unrelated to this issue.

I wonder if this part of the importFile that sets the author ID of every post to 1 is causing this problem:

https://github.com/WordPress/wordpress-playground/blob/31856c79e4e6a17eb7f6b7ab0f45874269040485/packages/playground/blueprints/src/lib/steps/import-file.ts#L66-L71

An easy fix would be to grab the ID of the first admin, then editor etc. and only use 1 if no other user is available. Let's go with that one.

A more involved but also permanent fix would be to pull in wp-cli and run the import command instead of providing a custom import implementation. Or, to avoid extra 4MB of downloads, at least copy over the import command from WP CLI. Let's do it in Blueprints v2.

CCing @bgrgicak – the error log says t.reason is undefined, it sounds like an issue with the reporter that also obscures the actual error message from WordPress.

318086865-428e0b16-0b58-4a91-a60b-3f162cddfe47

adamziel commented 5 months ago

Oh, the user with ID 1 actually relates to https://github.com/WordPress/wordpress-playground/issues/1161, not this issue.

adamziel commented 5 months ago

Thinking about this more, that entire Always use user ID=1 user mapping strategy used by the importFile step might be wrong and causing this and the other issue you've reported.

I just started a new high-priority issue to solve this and, hopefully, all other WXR problems reported so far:

https://github.com/WordPress/wordpress-playground/issues/1183