Skip to content

Fatal TypeError in class-dynamic-tags.php when processing arrays in render_tag() #4

@kbrookes

Description

@kbrookes

Description:

Bug Description

Fatal PHP error occurs when render_tag() receives an array instead of a string, specifically when processing featured images in Bricks query loops.

Error Message

Fatal error: Uncaught TypeError: strpos(): Argument #1 ($haystack) must be of type string, array given in
/wp-content/plugins/bricks-api-bridge/includes/class-dynamic-tags.php:79

Steps to Reproduce

  1. Create a Bricks query loop that displays posts
  2. Add an image element using {featured_image} dynamic data
  3. View the page on the frontend

Root Cause

In class-dynamic-tags.php line 79, the render_tag() method calls strpos($tag, '{bab_var:') without checking if $tag is a string. When Bricks passes image
metadata (an array) through the bricks/dynamic_data/render_tag filter, this causes a type error.

Proposed Fix

Add a type check at the beginning of the render_tag() method:

public function render_tag( $tag, $post, $context ) {
    // If $tag is not a string (e.g., array from image metadata), return it unchanged
    if ( ! is_string( $tag ) ) {
        return $tag;
    }

    if ( strpos( $tag, '{bab_var:' ) !== 0 ) {
        return $tag;
    }

    // ... rest of method
}

Environment

- Plugin Version: 1.0.0
- PHP Version: 7.4+
- Bricks Builder: Latest
- WordPress: 5.6+

Impact

This is a fatal error that crashes pages using query loops with featured images.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions