I got these errors under Last Comments in the dashboard after I upgraded to 2.8.1:
Warning: Cannot use a scalar value as an array in /home/foo/public_html/bar/wp-includes/post.php on line 820
Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/foo/public_html/bar/wp-includes/post.php on line 821
Warning: Invalid argument supplied for foreach() in /home/foo/public_html/bar/wp-includes/post.php on line 821
Warning: Cannot use a scalar value as an array in /home/foo/public_html/bar/wp-includes/post.php on line 823
They seem to appear only on my own comments.
After changing a line of code in post.php the error messages disappeared. But as I'm not exactly a PHP guru (that's an understatement), and this probably changes the behaviour of the blog when it comes to sanitation of inputs, I'd really like some help looking into it.
Is this a bug in WordPress, data corruption or something else? Any help would be appreciated.
Heres the original:
function sanitize_post($post, $context = 'display') {
if ( is_object($post) ) {
if ( !isset($post->ID) )
$post->ID = 0;
foreach ( array_keys(get_object_vars($post)) as $field )
$post->$field = sanitize_post_field($field, $post->$field, $post->ID, $context);
$post->filter = $context;
} else {
if ( !isset($post['ID']) )
$post['ID'] = 0;
foreach ( array_keys($post) as $field )
$post[$field] = sanitize_post_field($field, $post[$field], $post['ID'], $context);
$post['filter'] = $context;
}
return $post;
}
And this is what it looks like now:
function sanitize_post($post, $context = 'display') {
if ( is_object($post) ) {
if ( !isset($post->ID) )
$post->ID = 0;
foreach ( array_keys(get_object_vars($post)) as $field )
$post->$field = sanitize_post_field($field, $post->$field, $post->ID, $context);
$post->filter = $context;
} else if ( is_array($post) ) {
if ( !isset($post['ID']) )
$post['ID'] = 0;
foreach ( array_keys($post) as $field )
$post[$field] = sanitize_post_field($field, $post[$field], $post['ID'], $context);
$post['filter'] = $context;
}
return $post;
}