Open robin-scott opened 2 years ago
These items become errors in PHP 8.0 - and prevent a site with Rank Math Pro from updating PHP to latest version.
If you want I can add up the RankMath Pro error logs here?
Issue in RankMath Pro is resolved by:
$data = (is_array($data)) ? $data : [$data]; // add to line 240 of seo-by-rank-math-pro/includes/modules/schema/class-frontend.php
We're converting the string returned in this event into an array if it isn't already. This removes the warnings in PHP 7.4 and the errors in PHP 8.0 for RankMath Pro.
Got error 'PHP message: PHP Warning: foreach() argument must be of type array|object, string given in /wp-content/plugins/seo-by-rank-math/includes/modules/schema/class-frontend.php on line 101P
Fixed by adding
$schemas = (is_array($schemas)) ? $schemas : [$schemas]; // inserted as a new line 97 at /wp-content/plugins/seo-by-rank-math/includes/modules/schema/class-frontend.php
Hi @robin-scott The Schema data will always be in an array format. That's how it is stored in the postmeta table. On your site, for some reason, this schema data is stored in the wrong format. Did you import the Schema data from any other plugin?
If it is empty, or singular it is not an array. No, it wasn't imported. I'm describing the bug here. The error is fixed by making a non-array entry made by your plugin an array - which is a workaround.
Hello @robin-scott The issues you mentioned are fixed in the latest version. Please update the plugin.
Hello There is still a similar issue here : /includes/modules/instant-indexing/class-instant-indexing
The function get_log doesn't return always an array. Here I got false
from the option rank_math_indexnow_log
Fixed temporarily by adding this in function.php :
add_action('init', fn() => update_option('rank_math_indexnow_log', []));
It will be better if the get_log function ensure to return an array.
Describe the bug The following warnings are produced:
PHP Warning: array_filter() expects parameter 1 to be array, null given in /wp-content/plugins/seo-by-rank-math-pro/includes/modules/schema/class-frontend.php on line 248
Warning: array_filter() expects parameter 1 to be array, null given in /wp-content/plugins/seo-by-rank-math-pro/includes/modules/schema/class-frontend.php on line 248
PHP Warning: count(): Parameter must be an array or an object that implements Countable in /wp-content/plugins/seo-by-rank-math-pro/includes/modules/schema/class-frontend.php on line 251
Warning: count(): Parameter must be an array or an object that implements Countable in /public_html/wp-content/plugins/seo-by-rank-math-pro/includes/modules/schema/class-frontend.php on line 251
At latest release.
In order to use array_filter we should first check is_array or if exists - it's getting a null. In this case it's
$faq_data
from here: https://github.com/rankmath/seo-by-rank-math/blob/eea089f0afe7f476d1f9dadc1a9f75377373d282/includes/modules/schema/class-frontend.php#L249 - the item is returning a null.We also have invalid foreach for the line at:
https://github.com/rankmath/seo-by-rank-math/blob/eea089f0afe7f476d1f9dadc1a9f75377373d282/includes/modules/schema/class-jsonld.php#L174
This is also not null-proof at present.