• Resolved dev

    (@devksec)


    After updating to WordPress 6.5, pages using Spectra (UAG) blocks began crashing with the following fatal error:

    PHP Fatal error: Uncaught TypeError: array_intersect_key(): Argument #1 ($array) must be of type array, string given in /wp-includes/block-supports/layout.php

    Root Cause:
    Spectra blocks (especially uagb/container and UAGBCounter) are saving layout as a string, for example:

    "layout": "grid"

    However, as of recent WordPress core updates, layout must be an object, e.g.:

    "layout": { "type": "grid" }

    This results in a fatal crash during block rendering due to array_intersect_key() expecting an array.

    How We Identified It:

    • Issue only occurred on pages using Spectra blocks.
    • CLI and database checks confirmed multiple posts had "layout": "grid" or "layout": "number" stored directly in post_content.

    Please confirm if this has been addressed in the latest Spectra release, and whether future block saves will conform to the new expected format.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter dev

    (@devksec)

    Hi team,

    We’ve identified and resolved a critical issue affecting our WordPress site that we originally suspected might be related to Spectra blocks. Summary:

    We were encountering the following fatal error:

    nginx

    CopyEdit

    PHP Fatal error: Uncaught TypeError: array_intersect_key(): Argument #1 ($array) must be of type array, string given in /wp-includes/block-supports/layout.php:600+

    After extensive debugging, we’ve determined the actual cause was the core core/social-links block, which was passing parentLayout as a string ("flex") instead of the expected array structure. This led to array_intersect_key() being called on a string and crashing the page. Why this matters:

    Although Spectra blocks appeared to be involved initially (due to their heavy use of layout structures), the issue was unrelated to Spectra’s block rendering. Resolution:

    We patched WordPress core (layout.php) to add sanity checks before array_intersect_key() is called. Specifically:

    • We now confirm parentLayout and layout are arrays.
    • If not, we log the issue and safely skip processing to avoid breaking the page.

    This resolved the issue completely.

    mapmaker1

    (@mapmaker1)

    This error occurred again for me on a WordPress update. This time the error was logged in woocommerce plugin, but this is probably because of timing when the page is loaded. As devksec has said, it seems to be related to the Spectra block editor, and occurs on my pages where I have used the Spectra tab block. I resolved the issue in the same way as devksec, but I don’t know the root cause which is likely to do with the plugin.

    I had to edit function wp_render_layout_support_flag( $block_content, $block ) in public_html/wp-includes/block-supports/layout.php at line 570. The error was $parentLayout being passed as a string instead of an array causing a fatal error. In my modified code the cases where $layout and $parentLayout are not arrays is covered. My modified version is:

    $layout_0       = $block['attrs']['style']['layout'] ?? array();
    $parentLayout_0 = $block['parentLayout'] ?? array();

    $layout = is_array( $layout_0 ) ? $layout_0 : array();
    if ( ! is_array( $layout_0 ) ) {
    error_log( 'Expected $layout to be an array, got: ' . gettype( $layout_0 ) );
    }
    $parent_layout = is_array( $parentLayout_0 ) ? $parentLayout_0 : array();
    if ( ! is_array( $parentLayout_0 ) ) {
    error_log( 'Expected $parentLayout to be an array, got: ' . gettype( $parentLayout_0 ) );
    }

    $container_content_class = wp_unique_id_from_values(
    array(
    'layout' => array_intersect_key(
    $layout,
    array_flip( array( 'selfStretch', 'flexSize', 'columnStart', 'columnSpan', 'rowStart', 'rowSpan' ) )
    ),
    'parentLayout' => array_intersect_key(
    $parent_layout,
    array_flip( array( 'minimumColumnWidth', 'columnCount' ) )
    ),
    ),
    'wp-container-content-'
    );

    The original version was:

    $container_content_class = wp_unique_id_from_values(
    array(
    'layout' => array_intersect_key(
    $block['attrs']['style']['layout'] ?? array(),
    array_flip(
    array( 'selfStretch', 'flexSize', 'columnStart', 'columnSpan', 'rowStart', 'rowSpan' )
    )
    ),
    'parentLayout' => array_intersect_key(
    $block['parentLayout'] ?? array(),
    array_flip(
    array( 'minimumColumnWidth', 'columnCount' )
    )
    ),
    ),
    'wp-container-content-'
    );
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘WordPress 6.4 blocks issue – Fatal error’ is closed to new replies.