qtranslate / qtranslate-xt

qTranslate-XT (eXTended) - reviving qTranslate-X multilingual plugin for WordPress. A new community-driven plugin soon. Built-in modules for WooCommerce, ACF, slugs and others.
GNU General Public License v2.0
550 stars 103 forks source link

NextGen Gallery uploader not working #1266

Closed HoriaMarusca closed 1 year ago

HoriaMarusca commented 1 year ago

Intro: I am not a programmer, I am a (web) designer. I use the browser DevTools mainly to work on css styling. My knowledge in using debugging tools is limited.

The problem (probably similar with #1096?)

Environment:

Wordpress 6.1.1 PHP 8.0.26 Qtranslate XT ver 3.12.1 (with Yoast SEO 19.11, ACF 6.0.5, Slugs translation built-in modules activated) NextGen Gallery ver 3.3.0

Short description: Failing to upload images using the Nextgen upload function. The WordPress uploader works correctly.

Long description: The problem appears in the admin area of WordPress, only when using the Nextgen uploader. After dropping the files for upload (or selecting the files using the "Browser" button) and hitting the "Upload" button, the upload progress is shown as going from 0 to 100%, but in the end the upload fails.

The error message I get in the Chrome/Developer Tools/Network/Fetch/XHR is this one:

AssertionError thrown

language needs to be shown in url - cancelled by can_redirect, url_info={ "cookie_lang_front": "en", "cookie_front_or_admin_found": true, "scheme": "https", "host": "mywebsite", "path": "\/index.php", "query": "photocrati_ajax=1", "path-base": "", "doing_front_end": true, "wp-path": "\/index.php", "lang_cookie_front": "en", "doredirect": "language needs to be shown in url - cancelled by can_redirect", "language": "en", "set_cookie": true }

This might very well be a problem with NextGen, and not with Qtranslate XT. But if I deactivate the Qtranslate XT plugin, the problem disappears. I tried deactivating the Qtranslate XT built-in modules, but no luck. I also tried deactivating other plugins, again no luck. It's _"language needs to be shown in url"_ that makes me believe it is related to Qtranslate XT.
herrvigg commented 1 year ago

See also #1096 though it looks like a different issue.

HoriaMarusca commented 1 year ago

It looks like activating "Hide URL language information for default language" in qtranslate-XT options / General / URL Modification Mode solves the problem/

herrvigg commented 1 year ago

Thanks for the info, that's useful. I'll look into it.

HoriaMarusca commented 1 year ago

This is the error message sent by Wordpress that made me think of selecting the option with hiding the url (notice the double slash character between 'domain.com' and 'wp-admin'):

`Howdy!

WordPress caught an error with one of your plugins, qTranslate-XT.

The page where the error was caught (http://www.domain.com/wp-login.php?redirect_to=https://domain.com//wp-admin/) and check for any visible issues.

[...]

WordPress version 6.1.1 Active theme: custom Current plugin: qTranslate-XT (version 3.13.0) PHP version 8.2.4

Error Details

An error of type E_ERROR was caused in line 102 of the file .../wp-content/plugins/qtranslate-xt-3.13.0 - ian 05 2023/qtranslate_core.php. Error message: Uncaught AssertionError: language needs to be shown in url - cancelled by can_redirect, url_info={ "cookie_front_or_admin_found": false, "scheme": "http", "host": "domain.com", "path": "\/\/wp-login.php", "query": "redirect_to=https:\/\/domain.com\/\/wp-admin\/", "path-base": "", "doing_front_end": true, "wp-path": "\/\/wp-login.php", "lang_browser": "en", "doredirect": "language needs to be shown in url - cancelled by can_redirect", "language": "en", "set_cookie": true } in .../wp-content/plugins/qtranslate-xt-3.13.0 - ian 05 2023/qtranslate_core.php:102 Stack trace: 0 .../wp-content/plugins/qtranslate-xt-3.13.0 - ian 05 2023/qtranslate_core.php(102): assert() 1 .../wp-includes/class-wp-hook.php(308): qtranxf_init_language() 2 .../wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters() 3 .../wp-includes/plugin.php(517): WP_Hook->do_action() 4 .../wp-settings.php(480): do_action() 5 .../wp-config.php(89): require_once('/...') 6 .../wp-load.php(50): require_once('/...') 7 .../wp-login.php(12): require('/...') 8 {main} thrown`

herrvigg commented 1 year ago

The problem is clear, the requested URI is "wrong" in the sense it doesn't contain the language, but at the same time the request is not detected as AJAX by qTranslate.

I have a solution on the table, to check HTTP_X_REQUESTED_WITH = XMLHttpRequest (generally it's that value). I'm baffled this wasn't in place before... Checking DOING_AJAX is definitely not enough, this is only valid for the WordPress Ajax requests, but not for all the other plugins.

Even the assert on the redirect is wrong with Ajax requests. So there's quite a bit to fix and test here. But this could solve many related issues.

See also RFC6648: the X in HTTP_X_REQUESTED_WITH is deprecated so we should support both.

HoriaMarusca commented 1 year ago

Happy to help with testing, if needed, on my dev WordPress site (NextGen, Qtranslate XT, custom theme). That's pretty much where my area of expertise ends.

herrvigg commented 1 year ago

See #1326.

herrvigg commented 1 year ago

You can test from this tree: https://github.com/qtranslate/qtranslate-xt/tree/8c9e672040bb0acaa1c333ebcedab6080d70db21 I have not release it yet and it will go to upcoming 3.14.2. It's not merged in master yet because the hotfix is on the 3.14.x line and master is already in 3.15.x.

The main fix is trivial, it's only about removing an assert. But there's more behind the scenes. I first thought about a missed AJAX detection that is now mentioned in #1327 but that's actually a different topic.

herrvigg commented 1 year ago

Or even better with this, just with another minor fix but that should work the same: https://github.com/qtranslate/qtranslate-xt/tree/b2b7c1600d9fe1369e61b0622691eeb7c314046e

HoriaMarusca commented 1 year ago

Or even better with this, just with another minor fix but that should work the same: https://github.com/qtranslate/qtranslate-xt/tree/b2b7c1600d9fe1369e61b0622691eeb7c314046e

With the version above of qtranslate XT (b2b7c1600d) the NextGen Gallery specific uploader works as expected, no error upon uploading. No other problem noticed for the moment.

herrvigg commented 1 year ago

Great. I want to arrange a few things before releasing a fix as 3.14.2 that I want independent from the rolling updates in master that cover many other topics. I'll you know when it's up.

herrvigg commented 1 year ago

Fix released in 3.14.2 with other improvements for Ajax requests.