Fatal error in method advanced_robots_combine – foreach() receiving string inste

#1021654
  • Resolved Renan de Paula
    Rank Math free

    Issue Details
    We are facing an error on the website [Website URL] related to the Rank Math SEO plugin version 2.5. The error is being recorded by Sentry and is affecting the proper loading of pages in certain cases.

    Specific Error
    pgsql
    Copiar
    Editar
    Warning: foreach() argument must be of type array|object, string given
    Stack Trace
    The error occurs in the file /wp-content/plugins/seo-by-rank-math/includes/frontend/paper/class-paper.php on line 526, specifically inside the RankMath\Paper\Paper::advanced_robots_combine function.

    The full call stack is:

    RankMath\Paper\Paper::advanced_robots_combine (line 526)

    RankMath\Paper\Singular::get_post_advanced_robots (line 219)

    RankMath\Paper\Singular::advanced_robots (line 65)

    RankMath\Paper\Paper::advanced_robots (line 275)

    RankMath\Paper\Paper::get_robots (line 229)

    RankMath\Frontend\Head::robots (line 220)

    How to Reproduce
    The issue occurs when:

    A user accesses the website via a mobile device (case identified: iPhone with iOS 9.1 and Mobile Safari 9.0)

    WP Rocket is performing page preload

    The specific URL being accessed: https://www.donacoelha.com/meuapartamentinho/

    Technical Analysis
    In the advanced_robots_combine function, there is a foreach loop trying to iterate over the $advanced_robots variable:

    php
    Copiar
    Editar
    foreach ($advanced_robots as $key => $data) {
    The issue happens because $advanced_robots is coming as a string instead of an array/object. Specifically, this occurs when Post::get_meta(‘advanced_robots’, $this->object->ID) returns a string instead of an array.

    Environment
    WordPress: 6.8

    PHP: 8.1.32

    Rank Math SEO: 2.5

    Server: Linux 5.10.0-31-amd64

    Theme: Flatsome

    Other relevant plugins: WP Rocket

    Suggested Solution
    We recommend adding a type check before the foreach loop in the advanced_robots_combine function:

    php
    Copiar
    Editar
    // Line 526 in class-paper.php
    if (!is_array($advanced_robots) && !is_object($advanced_robots)) {
    return [];
    }

    foreach ($advanced_robots as $key => $data) {
    // existing code…
    }
    This verification would ensure the function does not attempt to iterate over a string, which is causing the current error.

    Additional Questions
    Has this issue been identified and addressed in any newer versions of the plugin?

    Are there any known incompatibilities between Rank Math SEO and WP Rocket during mobile preload?

    Is there any specific configuration that could be causing this behavior?

    Thank you in advance for your attention and support. I am available to provide any additional information if needed.

Viewing 1 replies (of 1 total)
  • Hello,

    Thank you for contacting Rank Math support.

    Please check and confirm you are using the latest versions of Rank Math according to our changelog: https://rankmath.com/changelog/

    It seems that you’re currently using the Rank Math PRO plugin, but the account you used to open this ticket is a free account.

    Can you please search and forward a receipt from FastSpring.com so we can locate your account and verify it?

    Looking forward to helping you.

    Thank you.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 1 replies (of 1 total)

The ticket ‘Fatal error in method advanced_robots_combine – foreach() receiving string inste’ is closed to new replies.