[wp-testers] a small problem, and possible solution, with get_post_custom_values

Krusty Ruffle krustyruffle at rustykruffle.com
Tue Dec 23 17:01:20 GMT 2008


Using WP 2.7, if you test for a custom value that is not there you will get
an Undefined Index Notice, (only when define('WP_DEBUG',true); of course.)

So, the Sandbox uses:

<?php if ( get_post_custom_values('comments') ) comments_template() // Add a
key+value of "comments" to enable comments on this page ?>

to test if the user wants comments on a page, if the 'comments' value it not
set then you get a notice.

If you go to wp-includes/post.php line #739 you see:

function get_post_custom_values( $key = '', $post_id = 0 ) {
    $custom = get_post_custom($post_id);

    return $custom[$key];
}

If you add one line like below, the notice goes away:

function get_post_custom_values( $key = '', $post_id = 0 ) {
    $custom = get_post_custom($post_id);

    if ( isset($custom[$key]) )
        return $custom[$key];
}

I'm sorry that I have no idea how to make and submit a patch, or if this is
the best solution, and I know this is a minor thing, I just thought someone
may be interested in knowing about it...

Thanks for reading :)


More information about the wp-testers mailing list