Invalid argument supplied for foreach in class-cmb2.php on line 304

#36142
  • Resolved Mick Levin
    Rank Math free

    Hello,

    Just tried to delete all post categories (left-overs from commercial theme’s demo-data), received white screen with thse 2 error messages:

    Warning: Invalid argument supplied for foreach() in /home/customer/www/XXX/public_html/wp-content/plugins/seo-by-rank-math/includes/class-cmb2.php on line 304

    Warning: Cannot modify header information – headers already sent by (output started at /home/customer/www/XXX/public_html/wp-content/plugins/seo-by-rank-math/includes/class-cmb2.php:304) in /home/customer/www/XXX/public_html/wp-includes/pluggable.php on line 1265

    After returning to the previous page (naturally, the list of post categories), I found the categories indeed were deleted. But my guess is that your plugin is doing some post-deletion checks, similar to what happens when I delete posts massively, to maybe warn about URLs.

    PS. The categories being deleted had 0 posts in each. So the scenario went as following: delete ALL posts, get a ton of URL warnings from your plugin. Then delete all categories, receive the white screen with the error.

    I think you can have a good idea how to reproduce the problem, and consequentially fix it.

    Thank you.
    Sincerely,
    Mick

Viewing 5 replies - 1 through 5 (of 5 total)
  • Todd
    Rank Math free

    Hi Mick,

    Thanks for getting in touch with us.

    I am so sorry for the trouble this must have caused.

    I tried to replicate the issue using the steps you gave but everything’s working normally for me without any problem. Here is a screencast:
    https://i.rankmath.com/YPN3Ro

    Did I do something different than you did or would this be somehow related to the theme you are using? In which case, would you mind sharing a link to the theme you are using?

    We look forward to hearing back from you.

    Thank you Todd,

    I’ve suspected as much, because a previously opened ticket by someone seemed had a similar symptom.

    PS. After this incident, I also tried to delete all categories of unused custom type in the same commercial theme (name is “Koral” by Upperthemes). Got the same white screen with the same error.

    Just looking at the code in the referred file, it happens to be a method called “sanitize_advanced_robots”, which does not validate a parameter called “$robots”, immediately treating it as an array.

    Maybe just doing a sanity check for the parameter, right after line #303, would make sense to avoid the error like that?

    Sincerely,
    Mick

    Hello,

    We might need to take a closer look at the settings. Please edit the first post on this ticket and include your WP logins in the designated Sensitive Data section.
    Sensitive Data Section

    It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:

    https://wordpress.org/plugins/temporary-login-without-password/

    You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):

    https://wordpress.org/plugins/wp-security-audit-log/

    We really look forward to helping you.

    Thank you Pratik,

    But I can not grant an access.

    I guess you will have to go by the error description and the file name and the line number, to make sure that this method does not crash WordPress because of a wrong type of a parameter.

    Have any developer actually looked through the error message, and the source code?

    I would expect this to be a quick fix, without fiddling with a customer site’s settings. The error is NOT in the settings, the error is in the code, and the code must be robust.

    Thank you.

    Todd
    Rank Math free

    Hi Mick,

    I see.

    It will take more time without the logins especially since we cannot replicate it.

    With that said, we will take a closer look and see if we can replicate it.

    If you need help with anything else, please open a new support ticket here so we can help.

    We are always here for assistance.

    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 5 replies - 1 through 5 (of 5 total)

The ticket ‘Invalid argument supplied for foreach in class-cmb2.php on line 304’ is closed to new replies.