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

Media import failure due to URL mismatch #107

Open
kevinburke opened this issue Sep 6, 2021 · 2 comments
Open

Media import failure due to URL mismatch #107

kevinburke opened this issue Sep 6, 2021 · 2 comments

Comments

@kevinburke
Copy link

kevinburke commented Sep 6, 2021

I'm attempting to copy media from my production site ("https://example.com") to my staging site on a different server ("https://stage.example.com"), using the "wp import" CLI tool.

The error message I got was very unclear at first - literally just "Failed to import Media" and the filename without any other information about what went wrong. If you search the "Support" history for this plugin, you see a ton of people asking for help relating to this error message.

Reading through the source code, I realized I could get more information by setting the IMPORT_DEBUG value to true. This told me that a valid URL was not being passed, which again was a little confusing because the URL is present in the XML file.

Further print line debugging made me realize that the issue is in wp_http_validate_url, which compares the URL for get_option('home') - in my case, the staging server - with the external URL - the production server. If these don't match, the media import will fail. I could imagine a lot of different reasons that you would want to import from a different URL externally, so it might be good to have an option to turn this flag off.

I tried setting the --url flag to wp import but this did not seem to have any effect.

In addition to making it possible to import from a URL with a different hostname than the value in get_option('home') it might be nice to improve the error message, or at least include more troubleshooting information to help people without the time or the means to go spelunking in the source code to figure out how to answer their problem.

@joyously
Copy link

joyously commented Sep 6, 2021

Is this code used by the CLI tool?

@kevinburke
Copy link
Author

Yes, "wp import" invokes this plugin. I'm not sure exactly of the mechanism, but if I add print statements to the source code for this plugin, and then run "wp import", the print statements appear in the output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants