WordPress.org

Make WordPress Core

Ticket #10905: 10905.diff

File 10905.diff, 571 bytes (added by scribu, 4 years ago)

add duplicate check for add_metadata()

  • wp-includes/meta.php

     
    3030 
    3131        $meta_value = maybe_serialize( stripslashes_deep($meta_value) ); 
    3232 
     33        // prevent duplicates 
     34        if ( $wpdb->get_var( $wpdb->prepare( 
     35                "SELECT COUNT(*) FROM $table WHERE meta_key = %s AND meta_value = %s AND $column = %d", 
     36                $meta_key, $meta_value, $object_id ) ) ) 
     37                return false; 
     38 
    3339        $wpdb->insert( $table, array( 
    3440                $column => $object_id, 
    3541                'meta_key' => $meta_key,