[wp-trac] [WordPress Trac] #65044: get_post_custom_values() missing array check, inconsistent with get_post_custom_keys()

WordPress Trac noreply at wordpress.org
Thu May 14 16:08:31 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 has-test-    |     Focuses:
  info has-unit-tests                            |
-------------------------------------------------+-------------------------

Comment (by ozgursar):

 == Patch Testing Report

 Patch Tested: https://github.com/WordPress/wordpress-develop/pull/11496

 === Environment
 - WordPress: 7.1-alpha-62161-src
 - PHP: 8.2.29
 - Server: nginx/1.29.4
 - Database: mysqli (Server: 8.4.7 / Client: mysqlnd 8.2.29)
 - Browser: Opera
 - OS: macOS
 - Theme: Twenty Twenty-Five 1.5
 - MU Plugins: None activated
 - Plugins:
   * Code Snippets 3.9.6
   * Test Reports 1.2.1

 === Steps taken
 1. Add the following code snippet to your active theme's `functions.php`
 or via Code Snippets plugin:

 {{{#!php
 add_action( 'init', function () {
     // Confirm what get_post_custom() returns for both PR cases
     unset( $GLOBALS['post'] );
     $case1 = get_post_custom( 0 );
     error_log( '[65044] Case 1 — invalid post ID 0: (' . gettype( $case1 )
 . ') ' . var_export( $case1, true ) );

     add_filter( 'get_post_metadata', '__return_empty_string', 1 );
     $case2 = get_post_custom( 1 );
     remove_filter( 'get_post_metadata', '__return_empty_string', 1 );
     error_log( '[65044] Case 2 — filter returns "": (' . gettype( $case2 )
 . ') ' . var_export( $case2, true ) );

     // Detect whether the is_array guard exists in get_post_custom_values
     $src = file_get_contents( ABSPATH . 'wp-includes/post.php' );
     preg_match( '/function get_post_custom_values.*?(?=\nfunction )/s',
 $src, $m );
     $guarded = isset( $m[0] ) && str_contains( $m[0], 'is_array' );
     error_log( '[65044] is_array guard in get_post_custom_values: ' . (
 $guarded ? 'PATCHED' : 'UNPATCHED' ) );
 } );
 }}}


 2. Ensure `WP_DEBUG` and `WP_DEBUG_LOG` are set to `true` in wp-
 config.php, then visit any page as an admin and check wp-content/debug.log
 3. Apply the patch and reload the page to observe the change in
 `debug.log`
 4. ✅ Patch is solving the problem

 === Expected result
 - debug.log before patch:

 [14-May-2026 15:55:09 UTC] [65044] Case 1 — invalid post ID 0: (boolean)
 false
 [14-May-2026 15:55:09 UTC] [65044] Case 2 — filter returns "": (string) ''
 [14-May-2026 15:55:09 UTC] [65044] is_array guard in
 get_post_custom_values: UNPATCHED


 - debug.log after patch:

 [14-May-2026 15:56:04 UTC] [65044] Case 1 — invalid post ID 0: (boolean)
 false
 [14-May-2026 15:56:04 UTC] [65044] Case 2 — filter returns "": (string) ''
 [14-May-2026 15:56:04 UTC] [65044] is_array guard in
 get_post_custom_values: PATCHED

 === Additional Notes
 - Case 1: `get_post_custom(0)` returns `false` because
 `get_metadata_raw()` short-circuits
   immediately when the post ID resolves to `0` (no global `$post`, no
 explicit ID passed).
 - Case 2: `get_post_custom()` returns `""` when a filter on
 `get_post_metadata` short-circuits the metadata lookup.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/65044#comment:12>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list