[wp-trac] [WordPress Trac] #65044: get_post_custom_values() missing array check, inconsistent with get_post_custom_keys()
WordPress Trac
noreply at wordpress.org
Tue Apr 21 03:38:27 UTC 2026
#65044: get_post_custom_values() missing array check, inconsistent with
get_post_custom_keys()
-------------------------------------------------+-------------------------
Reporter: saratheonline | Owner:
| saratheonline
Type: defect (bug) | Status: assigned
Priority: normal | Milestone: 7.1
Component: Posts, Post Types | Version: trunk
Severity: normal | Resolution:
Keywords: has-patch needs-testing needs-unit- | Focuses:
tests |
-------------------------------------------------+-------------------------
Comment (by liaison):
The sibling function get_post_custom_keys() already implements an
is_array() check. Adding the same check to get_post_custom_values()
prevents this invalid operation at the logic level rather than relying on
PHP's error suppression.
Testing on PHP 8.2.12 with E_ALL shows that while the function returns
null without crashing (thanks to the null coalescing operator), it still
performs an invalid offset access on a boolean when get_post_custom()
fails. This is a silent failure that violates defensive coding standards.
{{{#!php
<?php
add_action( 'wp_ajax_test_65044', function() {
$id = 999999;
$values = get_post_custom_values( 'some_key', $id );
var_dump(error_reporting());
wp_send_json_success( array( 'result' => $values ) );
});
}}}
[[Image(65044_ajax_test.png)]]
--
Ticket URL: <https://core.trac.wordpress.org/ticket/65044#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list