Make WordPress Core

Ticket #24726: 24726.3.diff

File 24726.3.diff, 2.6 KB (added by MikeHansenMe, 11 years ago)

Added Docs and Refresh

  • src/wp-includes/meta.php

     
    454454 *              specified meta_key. This parameter has no effect if meta_key is not specified.
    455455 * @return mixed Single metadata value, or array of values
    456456 */
    457 function get_metadata($meta_type, $object_id, $meta_key = '', $single = false) {
     457function get_metadata( $meta_type, $object_id, $meta_key = '', $single = false ) {
    458458        if ( ! $meta_type || ! is_numeric( $object_id ) ) {
    459459                return false;
    460460        }
     
    482482         */
    483483        $check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, $single );
    484484        if ( null !== $check ) {
    485                 if ( $single && is_array( $check ) )
     485                if ( $single && is_array( $check ) ) {
    486486                        return $check[0];
    487                 else
     487                } else {
    488488                        return $check;
     489                }
    489490        }
    490491
    491         $meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
     492        $meta_cache = wp_cache_get( $object_id, $meta_type . '_meta' );
    492493
    493         if ( !$meta_cache ) {
     494        if ( ! $meta_cache ) {
    494495                $meta_cache = update_meta_cache( $meta_type, array( $object_id ) );
    495496                $meta_cache = $meta_cache[$object_id];
    496497        }
     
    499500                return $meta_cache;
    500501        }
    501502
    502         if ( isset($meta_cache[$meta_key]) ) {
    503                 if ( $single )
    504                         return maybe_unserialize( $meta_cache[$meta_key][0] );
    505                 else
    506                         return array_map('maybe_unserialize', $meta_cache[$meta_key]);
     503        if ( isset( $meta_cache[ $meta_key ] ) ) {
     504                if ( $single ) {
     505                        $meta_value = maybe_unserialize( $meta_cache[ $meta_key ][0] );
     506                } else {
     507                        $meta_value = array_map( 'maybe_unserialize', $meta_cache[ $meta_key ] );
     508                }
     509        } else {
     510                if ( $single ) {
     511                        $meta_value = '';
     512                } else {
     513                        $meta_value = array();
     514                }
    507515        }
    508 
    509         if ($single)
    510                 return '';
    511         else
    512                 return array();
     516        /**
     517         * Filter whether to retrieve metadata of a specific type.
     518         *
     519         * The dynamic portion of the hook, `$meta_type`, refers to the meta
     520         * object type (comment, post, or user) and `$meta_key` refers to Meta key.
     521         * Returning a non-null value will effectively short-circuit the function.
     522         *
     523         * @since 4.3.0
     524         *
     525         * @param null|array|string $value     The value get_metadata() should
     526         *                                     return - a single metadata value,
     527         *                                     or an array of values.
     528         * @param int               $object_id Object ID.
     529         * @param string|array      $single    Meta value, or an array of values.
     530         */
     531        return apply_filters( "get_{$meta_type}_metadata-{$meta_key}", $meta_value, $object_id, $single );
    513532}
    514533
    515534/**