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

AJAX response error in Advanced Woo Search plugin under PHP8+ #1284

Closed Komarovski closed 1 year ago

Komarovski commented 1 year ago

Hey everyone,

Author of "Advanced Woo Search" plugin is asking - is qTranslate-XT provides some option to exclude some URLs from its language redirections?

Here's the link to a thread I've started on WP: https://wordpress.org/support/topic/ajax-doesnt-work-under-php8/#post-16451942

The problem is next, when I run website on PHP 7.4 "qTranslate-XT" and "Advanced Woo Search" works fine, but when I'm swithing to PHP 8+ versions and starting to search some products with "Advanced Woo Search", in browser console log I get an error: POST https://antik.ua/?wc-ajax=aws_action 500 jquery-3-6-0.min.js:2

After debuggin I saw that qTranslate-XT on PHP8+ trows an "CRITICAL Uncaught AssertionError".

2023-02-08T08:26:50+00:00 CRITICAL Uncaught AssertionError: detected in parse_language_info - cancelled by can_redirect, url_info={
"cookie_lang_front": "ru",
"cookie_front_or_admin_found": true,
"scheme": "https",
"host": "antik.ua",
"path": "\/",
"query": "wc-ajax=aws_action",
"path-base": "",
"doing_front_end": true,
"wp-path": "\/",
"language": "ru",
"doredirect": "detected in parse_language_info - cancelled by can_redirect",
"set_cookie": true
} in /home/antikua/antik.ua/www/wp-content/plugins/qtranslate-xt/qtranslate_core.php:102
Stack trace:

0 /home/antikua/antik.ua/www/wp-content/plugins/qtranslate-xt/qtranslate_core.php(102): assert(false, 'detected in par…')

1 /home/antikua/antik.ua/www/wp-includes/class-wp-hook.php(308): qtranxf_init_language('')

2 /home/antikua/antik.ua/www/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters(NULL, Array)

3 /home/antikua/antik.ua/www/wp-includes/plugin.php(517): WP_Hook->do_action(Array)

4 /home/antikua/antik.ua/www/wp-settings.php(480): do_action('plugins_loaded')

5 /home/antikua/antik.ua/www/wp-config.php(100): require_once('/home/antikua/a…')

6 /home/antikua/antik.ua/www/wp-load.php(50): require_once('/home/antikua/a…')

7 /home/antikua/antik.ua/www/wp-blog-header.php(13): require_once('/home/antikua/a…')

8 /home/antikua/antik.ua/www/index.php(17): require('/home/antikua/a…')

9 {main}

thrown in /home/antikua/antik.ua/www/wp-content/plugins/qtranslate-xt/qtranslate_core.php on line 102

Can anyone help me to understand what could lead to this error in PHP 8+ and didn't lead to such error in PHP 7.4?

Thanks!

herrvigg commented 1 year ago

That's annoying, there should be no redirection possible on AJAX calls. Nothing specific to PHP8 comes to my mind.

Komarovski commented 1 year ago

I have found that same "AssertionError" already was in PHP7 too, but in PHP8 it throws warning by default. Here's some info that I found about "AssertionError" in PHP8: https://php.watch/versions/8.0/assert-throws

Right now I have commented assert function in qtranslate_core.php on line 102. And everything's working on the frontend.

I think we should add some option that will allow users to turn on the development mode, and by default plugin will have production mode enabled - and all this assert checks will be ignored. Since not every hosting provides ability to change INI settings to disable assertation checks.

herrvigg commented 1 year ago

Can you check if you have HTTP_X_REQUESTED_WITH = XMLHttpRequest passed in the Ajax request? Or the same parameter without X.

I have no explanation about the PHP version though. You may compare the requests.

herrvigg commented 1 year ago

See #1326.

herrvigg commented 1 year ago

Fix released in 3.14.2.

I found the explanation about PHP8.0: https://php.watch/versions/8.0/assert-throws. The default setting of PHP INI has changed to assert.exception=1 from 0 before. That means the assert triggers an exception instead of a simple warning. This is poorly documented from the official PHP.net, nothing in the PHP8.0 release notes... only in a separate doc about PHP8.0 incompatibilties . See also this patch in github: https://github.com/php/php-src/pull/5925.

herrvigg commented 1 year ago

I missed your earlier response about exceptions in PHP8.0... but we came to the same conclusion :)

Komarovski commented 1 year ago

I missed your earlier response about exceptions in PHP8.0... but we came to the same conclusion :)

Hey Herr Vigg, sorry for late reply, yep, in latest version everything works fine with PHP8+, thank you very much for this fix! :)