• Hi,

    I’m getting a recurring PHP warning from EmbedPress on a production site.

    Environment

    • EmbedPress 4.6.6 (free version, no Pro)
    • WordPress 7.1.1
    • PHP 8.3.31
    • Rank Math SEO (generates the XML sitemaps)

    The warning
    PHP Warning: Undefined array key “html” in
    /wp-content/plugins/embedpress/EmbedPress/Gutenberg/EmbedPressBlockRenderer.php on line 1672

    It fires about 90 times a day (373 times over the last four days). Around 97% of the
    occurrences happen while Rank Math renders the XML sitemaps (/post-sitemap5.xml and
    similar, requested by search engine crawlers), the rest on single blog posts that
    contain Facebook and Instagram embeds.

    The cause
    In render_displayable_content() (line 1656), $embed can be either a string or an array,
    and the array is not guaranteed to contain an ‘html’ key:

    if (is_array($embed)) {
        echo $embed['html'];   // line 1672
    } else {
        echo $embed;
    }

    Two more spots in the same function make the same assumption:

    • Line 1661: $embed[‘html’] .= $styling[‘custom_branding’][‘html’];
      Same undefined key warning when custom branding is enabled.
    • Line 1668: $embed .= Helper::embed_content_share($content_id, $attributes);
      This concatenates a string onto $embed without checking whether it is an array. On
      PHP 8 that is a fatal TypeError (“Unsupported operand types: array . string”), not a
      warning. I have not hit it, presumably because content share is disabled here, but it
      looks like a crash waiting to happen for anyone who enables that option on a provider
      that returns an array.

    Suggested fix
    Normalising $embed to a string once, at the top of the function, would fix all three:

    private static function render_displayable_content($embed, $content_share, $content_id, $attributes, $styling = [])
    {
        $html = is_array($embed) ? ($embed['html'] ?? '') : (string) $embed;
    
        if (!empty($styling['custom_branding']['html'])) {
            $html .= $styling['custom_branding']['html'];
        }
    
        if (!empty($content_share)) {
            $html .= Helper::embed_content_share($content_id, $attributes);
        }
    
        echo $html;
    }

    One question: is it expected for a provider to return an array without an ‘html’ key, or
    does that point to an upstream problem in how the embed is fetched? If the array is
    malformed, silencing the warning would only hide the real issue.

    I’m happy to test a patch on this site if that helps.

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Amin

    (@amin7)

    Hi @metalinedev

    Greetings!

    Sorry for your experience. But, I could not replicate the issue on my side, but, I already informed the team, and we don’t want to simply suppress the warning and potentially hide the underlying issue. The dev team will investigate what $embed contains at the point where the warning occurs, particularly during the sitemap rendering process.

    Could you please provide the relevant debug.log entry with the $embed value logged when the warning occurs? That should help us determine whether the data is coming from an upstream provider response or from EmbedPress’s internal processing.

    Regarding the other quesry, I am sorry, I can’t confirm whether an array without an html key is an expected provider response or indicates incomplete data from the upstream embed request. So, I forwarded this one as well to the dev team. 🙂 I will inform you accordingly once I get the update fromm them.

    Thanks

    Plugin Support Amin

    (@amin7)

    Hi @metalinedev
    Greetings!
    I got an update from the dev team. They have fixed the PHP warning issue that you are facing earlier. 🙂 Please use the dev version of the free plugin from here, https://d.pr/f/zVxqKh and replace your current free plugin.

    Let me know how its going.

    Thanks

    Plugin Support Ashikur Rahman

    (@ashikurwp)

    Hi @metalinedev ,
    Greetings!

    We have not heard back from you since our last message, so I just wanted to follow up and check whether the issue is still occurring on your end. If you are still experiencing the same problem, please feel free to share any updates or additional information. We will be happy to assist you further.

    Looking forward to your response.

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.