Ticket #40012: 40012.diff
File 40012.diff, 2.2 KB (added by , 8 years ago) |
---|
-
src/wp-includes/meta.php
21 21 * @param int $object_id ID of the object metadata is for 22 22 * @param string $meta_key Metadata key 23 23 * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. 24 * @param bool$unique Optional, default is false.24 * @param mixed $unique Optional, default is false. 25 25 * Whether the specified metadata key should be unique for the object. 26 26 * If true, and the object already has a value for the specified metadata key, 27 27 * no change will be made. 28 * If 'value', and the object already has the same metadata value being added 29 * for the specified metadata key, no change will be made. 28 30 * @return int|false The meta ID on success, false on failure. 29 31 */ 30 32 function add_metadata($meta_type, $object_id, $meta_key, $meta_value, $unique = false) { … … 64 66 * @param int $object_id Object ID. 65 67 * @param string $meta_key Meta key. 66 68 * @param mixed $meta_value Meta value. Must be serializable if non-scalar. 67 * @param bool$unique Whether the specified meta key should be unique69 * @param mixed $unique Whether the specified meta key should be unique 68 70 * for the object. Optional. Default false. 69 71 */ 70 72 $check = apply_filters( "add_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $unique ); 71 73 if ( null !== $check ) 72 74 return $check; 73 75 74 if ( $unique && $wpdb->get_var( $wpdb->prepare( 75 "SELECT COUNT(*) FROM $table WHERE meta_key = %s AND $column = %d", 76 $meta_key, $object_id ) ) ) 77 return false; 76 if ( false !== $unique ) { 77 if ( 'value' === $unique ) { 78 $sql = $wpdb->prepare( "SELECT COUNT(*) FROM {$table} WHERE meta_key = %s AND meta_value = %s AND {$column} = %d", $meta_key, $meta_value, $object_id ); 79 } else { 80 $sql = $wpdb->prepare( "SELECT COUNT(*) FROM {$table} WHERE meta_key = %s AND {$column} = %d", $meta_key, $meta_value, $object_id ); 81 } 78 82 83 if ( $wpdb->get_var( $sql ) ) { 84 return false; 85 } 86 } 87 79 88 $_meta_value = $meta_value; 80 89 $meta_value = maybe_serialize( $meta_value ); 81 90