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

DD32 wordpress at dd32.id.au
Tue Dec 23 22:52:18 GMT 2008


Hah, I submitted that inside another patch a few days ago! :)

http://trac.wordpress.org/attachment/ticket/8705/8705.diff

2008/12/24 Krusty Ruffle <krustyruffle at rustykruffle.com>

> 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 :)
> _______________________________________________
> wp-testers mailing list
> wp-testers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-testers
>


More information about the wp-testers mailing list