WordPress.org

Make WordPress Core

Ticket #14766: wp-includes-meta-filters-fixed.patch

File wp-includes-meta-filters-fixed.patch, 3.0 KB (added by sc0ttkclark, 10 years ago)

Fixing delete use of $meta_value vs $_meta_value as used in other meta saving actions; Removed use of maybe_unserialize in get_metadata; Now $meta_value uses stripslashes_deep before filters are called in add / update / delete

  • wp-includes/meta.php

     
    4444
    4545        // expected_slashed ($meta_key)
    4646        $meta_key = stripslashes($meta_key);
     47        $meta_value = stripslashes_deep($meta_value);
    4748
    4849        $check = apply_filters( "add_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $unique );
    4950        if ( null !== $check )
     
    5556                return false;
    5657
    5758        $_meta_value = $meta_value;
    58         $meta_value = maybe_serialize( stripslashes_deep($meta_value) );
     59        $meta_value = maybe_serialize( $meta_value );
    5960
    6061        do_action( "add_{$meta_type}_meta", $object_id, $meta_key, $_meta_value );
    6162
     
    111112
    112113        // expected_slashed ($meta_key)
    113114        $meta_key = stripslashes($meta_key);
     115        $meta_value = stripslashes_deep($meta_value);
    114116
    115117        $check = apply_filters( "update_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $prev_value );
    116118        if ( null !== $check )
     
    129131        }
    130132
    131133        $_meta_value = $meta_value;
    132         $meta_value = maybe_serialize( stripslashes_deep($meta_value) );
     134        $meta_value = maybe_serialize( $meta_value );
    133135
    134136        $data  = compact( 'meta_value' );
    135137        $where = array( $column => $object_id, 'meta_key' => $meta_key );
     
    186188        $id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id';
    187189        // expected_slashed ($meta_key)
    188190        $meta_key = stripslashes($meta_key);
    189         $meta_value = maybe_serialize( stripslashes_deep($meta_value) );
     191        $meta_value = stripslashes_deep($meta_value);
    190192
    191193        $check = apply_filters( "delete_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $delete_all );
    192194        if ( null !== $check )
    193195                return (bool) $check;
    194196
     197        $_meta_value = $meta_value;
     198        $meta_value = maybe_serialize( $meta_value );
     199
    195200        $query = $wpdb->prepare( "SELECT $id_column FROM $table WHERE meta_key = %s", $meta_key );
    196201
    197202        if ( !$delete_all )
     
    204209        if ( !count( $meta_ids ) )
    205210                return false;
    206211
    207         do_action( "delete_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $meta_value );
     212        do_action( "delete_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value );
    208213
    209214        $query = "DELETE FROM $table WHERE $id_column IN( " . implode( ',', $meta_ids ) . " )";
    210215
     
    218223        if ( 'user' == $meta_type )
    219224                clean_user_cache($object_id);
    220225
    221         do_action( "deleted_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $meta_value );
     226        do_action( "deleted_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value );
    222227
    223228        return true;
    224229}
     
    245250
    246251        $check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, $single );
    247252        if ( null !== $check ) {
    248                 if ( !is_array( $check ) )
     253                if ( $single && is_array( $check ) )
     254                        return $check[0];
     255                else
    249256                        return $check;
    250                 elseif ( $single )
    251                         return maybe_unserialize( $check[0] );
    252                 else
    253                         return array_map( 'maybe_unserialize', $check );
    254257        }
    255258
    256259        $meta_cache = wp_cache_get($object_id, $meta_type . '_meta');