Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

PHP warning in generateblocks Pro

  • 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 456

    Looking 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_type is returning this array:

    (
        [0] => product
    )

    hence $location[] = 'archive:' . $post_type triggers a warning in PHP 8+, which pollutes the error log.

  • Hello.

    Can you please describe the steps you followed in order to get the warning? Were you trying to add a condition?

  • 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_type returns 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.

  • 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:

    1. Which version of GenerateBlocks Pro are you running?
    2. Which PHP version exactly?
    3. 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!

  • 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.

  • Hi there,

    Sure, no problem, thanks for letting me know!

  • 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_type variable 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_DEBUG enabled.

    Based on this, I believe we can safely close the ticket.

    Thank you.

  • Ah ok, glad you found a solution then!

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.