Ticket #16267: post_meta.patch
File post_meta.patch, 3.6 KB (added by , 10 years ago) |
---|
-
meta.php
93 93 * @param string $meta_value Metadata value 94 94 * @param string $prev_value Optional. If specified, only update existing metadata entries with 95 95 * the specified value. Otherwise, update all entries. 96 * @param int $metaId ID of the metadata, Optional. If specified, only update existing metadata entry with 97 * the specified value. Otherwise, update all entities or entities where $prev_value is specified. 96 98 * @return bool True on successful update, false on failure. 97 99 */ 98 function update_metadata($meta_type, $object_id, $meta_key, $meta_value, $prev_value = '' ) {100 function update_metadata($meta_type, $object_id, $meta_key, $meta_value, $prev_value = '', $metaId = '') { 99 101 if ( !$meta_type || !$meta_key ) 100 102 return false; 101 103 … … 141 143 $where['meta_value'] = $prev_value; 142 144 } 143 145 144 do_action( "update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value ); 146 if ( !empty( $metaId ) ) { 147 $metaId = intval($metaId); 148 $where['meta_id'] = $metaId; 149 } 145 150 151 do_action( "update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value, $metaId ); 152 146 153 $wpdb->update( $table, $data, $where ); 147 154 wp_cache_delete($object_id, $meta_type . '_meta'); 148 155 // users cache stores usermeta that must be cleared. 149 156 if ( 'user' == $meta_type ) 150 157 clean_user_cache($object_id); 151 158 152 do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value );159 do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value, $metaId ); 153 160 154 161 return true; 155 162 } … … 323 330 324 331 // Get meta info 325 332 $id_list = join(',', $ids); 326 $meta_list = $wpdb->get_results( $wpdb->prepare("SELECT $column, meta_key, meta_value FROM $table WHERE $column IN ($id_list)",333 $meta_list = $wpdb->get_results( $wpdb->prepare("SELECT $column, meta_key, meta_value, meta_id FROM $table WHERE $column IN ($id_list)", 327 334 $meta_type), ARRAY_A ); 328 335 329 336 if ( !empty($meta_list) ) { … … 331 338 $mpid = intval($metarow[$column]); 332 339 $mkey = $metarow['meta_key']; 333 340 $mval = $metarow['meta_value']; 341 $mid = intval($metarow['meta_id']); 334 342 335 343 // Force subkeys to be array type: 336 344 if ( !isset($cache[$mpid]) || !is_array($cache[$mpid]) ) … … 338 346 if ( !isset($cache[$mpid][$mkey]) || !is_array($cache[$mpid][$mkey]) ) 339 347 $cache[$mpid][$mkey] = array(); 340 348 341 // Add a value to the current pid/key:342 $cache[$mpid][$mkey][] = $mval;349 // Add a meta id and value to the current pid/key: 350 $cache[$mpid][$mkey][] = array('id' => $mid, 'value' => $mval); 343 351 } 344 352 } 345 353 -
post.php
1441 1441 * @param string $meta_key Metadata key. 1442 1442 * @param mixed $meta_value Metadata value. 1443 1443 * @param mixed $prev_value Optional. Previous value to check before removing. 1444 * @param mixed $meta_id Optional. Meta ID value to check before changing. 1444 1445 * @return bool False on failure, true if success. 1445 1446 */ 1446 function update_post_meta($post_id, $meta_key, $meta_value, $prev_value = '' ) {1447 function update_post_meta($post_id, $meta_key, $meta_value, $prev_value = '', $meta_id = '') { 1447 1448 // make sure meta is added to the post, not a revision 1448 1449 if ( $the_post = wp_is_post_revision($post_id) ) 1449 1450 $post_id = $the_post; 1450 1451 1451 return update_metadata('post', $post_id, $meta_key, $meta_value, $prev_value );1452 return update_metadata('post', $post_id, $meta_key, $meta_value, $prev_value, $meta_id); 1452 1453 } 1453 1454 1454 1455 /**