-
lsitlabs
Hi,
I am getting this warning in PHP error log:
Array to string conversion in /home/xxxxxxx/public_html/wp-content/plugins/generateblocks-pro/includes/conditions/conditions/class-condition-location.php on line 456Looking at the code referenced in the warning, the problem seems to be here:
elseif ( $wp_the_query->is_post_type_archive ?? is_post_type_archive() ) { $post_type = isset( $wp_the_query ) ? $wp_the_query->get( 'post_type' ) : get_query_var( 'post_type' ); if ( $post_type ) { $location[] = 'archive:' . $post_type; }As when this happens
$post_typeis returning this array:( [0] => product )hence
$location[] = 'archive:' . $post_typetriggers a warning in PHP 8+, which pollutes the error log. -
George
Hello.
Can you please describe the steps you followed in order to get the warning? Were you trying to add a condition?
-
lsitlabs
Hi George,
I added a condition which includes location, so the post type is being evaluated.
As I mentioned above, the issue is that
$post_typereturns an array and in the part of code I referenced in my previous message handles as a string in line 456, so this triggers a warning. -
George
Hi,
Thanks for the additional details.It definitely looks like a bug.
I haven’t been able to reproduce this on my end with PHP 8.4.5, though. Could you confirm:
- Which version of GenerateBlocks Pro are you running?
- Which PHP version exactly?
- Is this happening on the frontend when visiting the shop/product archive, or in the admin when editing the condition?
If you’re comfortable sharing, a copy of the exact condition setup (screenshot or export) would help narrow it down.
Thanks!
-
lsitlabs
Hi George,
Thanks for checking this out.
To answer your questions:
1. GB Pro 2.5
2. PHP 8.3.30
3. Happens on frontend
4. This is the JSON of the condition:{ "logic": "OR", "groups": [ { "logic": "AND", "conditions": [ { "type": "user_role", "rule": "general:logged_out", "operator": "is", "value": "" }, { "type": "location", "rule": "post:product", "operator": "is", "value": "" } ] } ] }That said, please allow me 24–48 hours to investigate further before you spend more time on this. Since you’re unable to replicate the issue, I’d like to create a fresh development copy of the site and run a few tests.
We use a live search feature with predictive suggestions and autocomplete as users type, and I want to verify whether it could be affecting the query in any way.
-
George
Hi there,
Sure, no problem, thanks for letting me know!
-
lsitlabs
Hi George,
I’ve carried out some additional testing and have been able to isolate the issue.
It is not caused by GenerateBlocks, but by the mega menu plugin we currently use. When the plugin is active, the
$post_typevariable is returned as an array instead of a string.I’m not sure why a mega menu plugin alters the WP Query in this way. In any case, this is not something I need to investigate further, as we were already in the process of replacing it with an overlay panels–based solution for managing the mega menu.
This is actually how we came across the warning in the first place: while testing the new setup on a staging site with
WP_DEBUGenabled.Based on this, I believe we can safely close the ticket.
Thank you.
-
George
Ah ok, glad you found a solution then!
- You must be logged in to reply to this topic.