Skip to content

Commit 34f2b9c

Browse files
Posts, Post Types: Fix missing array check in get_post_custom_values().
Posts, Post Types: Fix missing array check in get_post_custom_values(). `get_post_custom()` can return `false` for an invalid post ID or an empty string for a non-existing post. `get_post_custom_values()` accessed the result as an array without first verifying it is one, triggering a PHP warning on PHP 8+. Adds an `is_array()` guard consistent with the sibling function `get_post_custom_keys()`, which already handles this case correctly.
1 parent e12ddb3 commit 34f2b9c

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

src/wp-includes/post.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2891,6 +2891,10 @@ function get_post_custom_values( $key = '', $post_id = 0 ) {
28912891

28922892
$custom = get_post_custom( $post_id );
28932893

2894+
if ( ! is_array( $custom ) ) {
2895+
return null;
2896+
}
2897+
28942898
return $custom[ $key ] ?? null;
28952899
}
28962900

0 commit comments

Comments
 (0)