wpdreams / ajax-search-pro-development

Issues and dev tracking repository for Ajax Search Pro for WordPress plugin
0 stars 0 forks source link

WPML and Ajax Search Pro Issues in PHP 8.2 #68

Open kswro opened 11 months ago

kswro commented 11 months ago

Describe the bug Search does not work when WPML compatibility feature is enabled in PHP 8.2 env (WordPress 6.4 recommended to run on PHP 8.1 or 8.2). Message that appears when searching: "The request failed. Please check your connection! Status: 500"

The issue does not appear in PHP 7.4

To Reproduce WPML Info & Config:

Ajax Search Pro Info & Config:

WordPress Info:

Steps to reproduce the behavior:

  1. Search (in my case using shortcode)
  2. See error

Expected behavior Search returns results as in PHP 7.4 env.

Desktop (please complete the following information):

Log

[08-Nov-2023 02:20:47 UTC] PHP Fatal error:  Uncaught TypeError: Illegal offset type in isset or empty in /home/customer/www/.../public_html/wp-content/plugins/sitepress-multilingual-cms/classes/url-handling/converter/class-wpml-url-cached-converter.php:46
Stack trace:
#0 /home/customer/www/.../public_html/wp-content/plugins/sitepress-multilingual-cms/classes/url-handling/converter/class-wpml-url-converter.php(149): WPML_URL_Cached_Converter->get_language_from_url(Object(WP_Error))
#1 /home/customer/www/.../public_html/wp-content/plugins/sitepress-multilingual-cms/classes/url-handling/converter/class-wpml-url-cached-converter.php(33): WPML_URL_Converter->convert_url(Object(WP_Error), 'en')
#2 /home/customer/www/.../public_html/wp-content/plugins/sitepress-multilingual-cms/classes/API/Hooks/class-wpml-api-hook-permalink.php(37): WPML_URL_Cached_Converter->convert_url(Object(WP_Error), 'en')
#3 /home/customer/www/.../public_html/wp-includes/class-wp-hook.php(324): WPML_API_Hook_Permalink->wpml_permalink_filter(Object(WP_Error), 'en')
#4 /home/customer/www/.../public_html/wp-includes/plugin.php(205): WP_Hook->apply_filters(Object(WP_Error), Array)
#5 /home/customer/www/.../public_html/wp-content/plugins/ajax-search-pro/includes/classes/Search/SearchTaxonomyTerms.php(470): apply_filters('wpml_permalink', Object(WP_Error), 'en')
#6 /home/customer/www/.../public_html/wp-content/plugins/ajax-search-pro/includes/classes/Search/AbstractSearch.php(104): WPDRMS\ASP\Search\SearchTaxonomyTerms->postProcess()
#7 /home/customer/www/.../public_html/wp-content/plugins/ajax-search-pro/includes/classes/Query/SearchQuery.php(911): WPDRMS\ASP\Search\AbstractSearch->search('tes')
#8 /home/customer/www/.../public_html/wp-content/plugins/ajax-search-pro/includes/classes/Query/SearchQuery.php(470): WPDRMS\ASP\Query\SearchQuery->get_posts()
#9 /home/customer/www/.../public_html/wp-content/plugins/ajax-search-pro/includes/classes/Hooks/Ajax/Search.php(60): WPDRMS\ASP\Query\SearchQuery->__construct(Array, 5, Array)
#10 /home/customer/www/.../public_html/wp-includes/class-wp-hook.php(324): WPDRMS\ASP\Hooks\Ajax\Search->handle('')
#11 /home/customer/www/.../public_html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters('', Array)
#12 /home/customer/www/.../public_html/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#13 /home/customer/www/.../public_html/wp-admin/admin-ajax.php(203): do_action('wp_ajax_nopriv_...')
#14 {main}
  thrown in /home/customer/www/.../public_html/wp-content/plugins/sitepress-multilingual-cms/classes/url-handling/converter/class-wpml-url-cached-converter.php on line 46

Additional context I contacted WPML support and this is their reply: https://wpml.org/forums/topic/wpml-and-ajax-search-pro-issues-in-php-8-2/

ernestmarcinko commented 11 months ago

Hi,

Thank you for the detailed report. I see an issue right away, and it looks like it is unrelated to either of the plugins, and is very likely not a bug in either.

This line tells a lot to me:

apply_filters('wpml_permalink', Object(WP_Error), 'en')

This is how the permalink is requested from WPML via the wpml_permalink hook. However notice the first argument, it is WP_Error object, which should be the link to the taxonomy term. That means, the original link requested from WordPress returned an Error instead of the actual link - Ajax Search Pro just passes it towards to the hook.

That error object is causing the problem. Usually WordPress only returns an error object if there is an issue with the requested resource, in this case it seems like the link for one particular term (or more terms) is not possible to request, or it is not meant to be requested.

On the Search Sources -> Taxonomy Terms Search panel, check the list of the selected taxonomies to search there is definitely one or more selected that should not be. Some taxonomies are not meant to be returned as results (non-archive), so they can't have a link to them. They shouldn't show up on the list by default, but in some cases they can't be filtered out.

Make sure to check that list and deselect the ones that should not be shown as results:

image

That will resolve this issue.

ernestmarcinko commented 11 months ago

I forgot - you also mentioned the PHP version, it is possible that there is a hook for the taxonomy term links somewhere else, which then bugs them out and wordpress catches it and returns an error when it's requested. Could be a deprecated function of some sort, which may not longer work on PHP 8.2.

Ajax Search Pro requests it via get_term_link() core WP function, and that sent an error object instead of the link, which was then passed on to the WPML hook.

kswro commented 11 months ago

Hi ernestmarcinko, thanks for the response.

On the Search Sources -> Taxonomy Terms Search panel, check the list of the selected taxonomies to search there is definitely one or more selected that should not be. Some taxonomies are not meant to be returned as results (non-archive), so they can't have a link to them. They shouldn't show up on the list by default, but in some cases they can't be filtered out.

From the start, I did not enable taxonomy term search. I also just confirmed in the Taxonomy Terms Search Panel that there is no taxonomy selected to search (it's blank, just as seen in your screenshot above).

it is possible that there is a hook for the taxonomy term links somewhere else, which then bugs them out and wordpress catches it and returns an error when it's requested. Could be a deprecated function of some sort, which may not longer work on PHP 8.2.

Yes, I believe this is caused by breaking changes due to the upgrade to PHP 8. It's just that I don't know where the error lies because it involves 2 plugins and WordPress core itself. For now I will stick with PHP 7.4.

kswro commented 11 months ago

That error object is causing the problem. Usually WordPress only returns an error object if there is an issue with the requested resource, in this case it seems like the link for one particular term (or more terms) is not possible to request, or it is not meant to be requested.

Btw, in your opinion, is this kind of workaround (link below) related to this issue, and can it also be applied to ASP? At a glance, I saw that there was a similarity to the fatal error message in this case.

https://wpml.org/errata/the-events-calendar-fatal-error-on-translated-events-with-php-8/

ernestmarcinko commented 11 months ago

From the start, I did not enable taxonomy term search. I also just confirmed in the Taxonomy Terms Search Panel that there is no taxonomy selected to search (it's blank, just as seen in your screenshot above). That is strange, because the error specifically originates from the Taxonomy search file, maybe it is the keyword suggestions then?

Can you please turn that off or deselect some taxonomies here: image

But this feels like some sort of a WP core issue. Looking at that other one you linked, it is very similar and that workaround would work here too. However that is only a "bypass" and it's redundant, as it does not reveal why the link is returned as an error instead of like an empty string or something like that.

Either way, I am keeping this open and possibly add that workaround to address the issue. It is redundant, but at this point I think it's just easier to add those few lines, and let the WP core team figure out what's happening. This surely comes up to others as well, so it is likely going to be fixed in some time.

kswro commented 10 months ago

That is strange, because the error specifically originates from the Taxonomy search file, maybe it is the keyword suggestions then? Can you please turn that off or deselect some taxonomies here:

Sorry for my late reply.

Yes, I can confirm that by disabling the predictive results and keyword suggestions feature, ASP and WPML run normally in PHP 8.2. At least during a short observation after disabling the feature, I didn't see anything in the error_log.

Before this, I activated this feature with a keyword suggestion source that came from "post title".

ernestmarcinko commented 10 months ago

Very good, thank you! I will look at the WP Core bugs list, maybe I can find something in relation. Either way, I am going to add an error check for all search types, just in case.

DEV TODO:

kswro commented 10 months ago

It seems I spoke too quickly.

The search was able to run normally (with the previous feature disabled) before, but I again faced the same problem with an identical error_log as before. I don't understand why it used to work normally but doesn't anymore.

Currently, I'm back to using PHP 7.4.

ernestmarcinko commented 10 months ago

@kswro All right, either way, the error check is going to fix this for sure. Thank you very much for all the feedback, it was very useful!