WordPress.org

Make WordPress Core

Ticket #10803: meta-default.patch

File meta-default.patch, 3.4 KB (added by azaozz, 9 years ago)
  • wp-includes/comment.php

     
    414414 * @param int $comment_id Post ID.
    415415 * @param string $key The meta key to retrieve.
    416416 * @param bool $single Whether to return a single value.
    417  * @return mixed Will be an array if $single is false. Will be value of meta data field if $single
    418  *  is true.
     417 * @param mixed $default What to return when metadata doesn't exist.
     418 * @return mixed Will be an array if $single is false and $default is not set.
     419 *  Will be value of meta data field or $default if no metadata exist.
    419420 */
    420 function get_comment_meta($comment_id, $key, $single = false) {
    421         return get_metadata('comment', $comment_id, $key, $single);
     421function get_comment_meta($comment_id, $key, $single = false, $default = false) {
     422        if ( !$single && $default === false )
     423                $default = array();
     424
     425        return get_metadata('comment', $comment_id, $key, $single, $default);
    422426}
    423427
    424428/**
     
    885889function wp_untrash_comment($comment_id = 0) {
    886890        do_action('untrash_comment', $comment_id);
    887891
    888         $comment = array('comment_ID'=>$comment_id, 'comment_approved'=>'0');
     892        $comment = array('comment_ID'=>$comment_id);
    889893
    890         //Either set comment_approved to the value in comment_meta or worse case to false which will mean moderation
    891         $comment['comment_approved'] = get_comment_meta($comment_id, '_wp_trash_meta_status', true);
     894        //Either set comment_approved to the value in comment_meta or worse case to 0 which will mean moderation
     895        $comment['comment_approved'] = get_comment_meta($comment_id, '_wp_trash_meta_status', true, '0');
    892896
    893897        wp_update_comment($comment);
    894898
  • wp-includes/meta.php

     
    118118        return true;
    119119}
    120120
    121 function get_metadata($meta_type, $object_id, $meta_key = '', $single = false) {
     121function get_metadata($meta_type, $object_id, $meta_key = '', $single = false, $default = false) {
    122122        if ( !$meta_type )
    123                 return false;
     123                return $default;
    124124
    125125        $meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
    126126
     
    140140                }
    141141        }
    142142
    143         if ($single)
    144                 return '';
    145         else
    146                 return array();
     143        return $default;
    147144}
    148145
    149146function update_meta_cache($meta_type, $object_ids) {
  • wp-includes/post.php

     
    552552 * @param int $post_id Post ID.
    553553 * @param string $key The meta key to retrieve.
    554554 * @param bool $single Whether to return a single value.
    555  * @return mixed Will be an array if $single is false. Will be value of meta data field if $single
    556  *  is true.
     555 * @param mixed $default What to return when metadata doesn't exist.
     556 * @return mixed Will be an array if $single is false and $default is not set.
     557 *  Will be value of meta data field or $default if no metadata exist.
    557558 */
    558 function get_post_meta($post_id, $key, $single = false) {
    559         return get_metadata('post', $post_id, $key, $single);
     559function get_post_meta($post_id, $key, $single = false, $default = false) {
     560        if ( !$single && $default === false )
     561                $default = array();
     562
     563        return get_metadata('post', $post_id, $key, $single, $default);
    560564}
    561565
    562566/**