Ticket #18196: 18196-v2.diff
File 18196-v2.diff, 5.7 KB (added by , 13 years ago) |
---|
-
wp-includes/post.php
1497 1497 * @return bool Whether the post meta key was deleted from the database 1498 1498 */ 1499 1499 function delete_post_meta_by_key($post_meta_key) { 1500 if ( !$post_meta_key ) 1501 return false; 1502 1503 global $wpdb; 1504 $post_ids = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT post_id FROM $wpdb->postmeta WHERE meta_key = %s", $post_meta_key)); 1505 if ( $post_ids ) { 1506 $postmetaids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = %s", $post_meta_key ) ); 1507 $in = implode( ',', array_fill(1, count($postmetaids), '%d')); 1508 do_action( 'delete_postmeta', $postmetaids ); 1509 $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_id IN($in)", $postmetaids )); 1510 do_action( 'deleted_postmeta', $postmetaids ); 1511 foreach ( $post_ids as $post_id ) 1512 wp_cache_delete($post_id, 'post_meta'); 1513 return true; 1514 } 1515 return false; 1500 return delete_metadata( 'post', null, $post_meta_key, '', true ); 1516 1501 } 1517 1502 1518 1503 /** -
wp-includes/meta.php
149 149 } 150 150 151 151 do_action( "update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value ); 152 153 if ( 'post' == $meta_type ) 154 do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); 152 155 153 156 $wpdb->update( $table, $data, $where ); 154 157 … … 158 161 clean_user_cache($object_id); 159 162 160 163 do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value ); 164 165 if ( 'post' == $meta_type ) 166 do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); 161 167 162 168 return true; 163 169 } … … 218 224 return false; 219 225 220 226 do_action( "delete_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value ); 221 227 228 if ( 'post' == $meta_type ) 229 do_action( 'delete_postmeta', $meta_ids ); 230 222 231 $query = "DELETE FROM $table WHERE $id_column IN( " . implode( ',', $meta_ids ) . " )"; 223 232 224 233 $count = $wpdb->query($query); 225 234 226 235 if ( !$count ) … … 232 241 clean_user_cache($object_id); 233 242 234 243 do_action( "deleted_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value ); 244 245 if ( 'post' == $meta_type ) 246 do_action( 'deleted_postmeta', $meta_ids ); 235 247 236 248 return true; 237 249 } … … 381 393 $where[$id_column] = $meta_id; 382 394 383 395 do_action( "update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value ); 396 397 if ( 'post' == $meta_type ) 398 do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); 384 399 385 400 // Run the update query, all fields in $data are %s, $where is a %d. 386 401 $result = (bool) $wpdb->update( $table, $data, $where, '%s', '%d' ); … … 394 409 395 410 do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value ); 396 411 412 if ( 'post' == $meta_type ) 413 do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); 414 397 415 return $result; 398 416 } 399 417 … … 436 454 437 455 do_action( "delete_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value ); 438 456 457 if ( 'post' == $meta_type ) 458 do_action( 'delete_postmeta', $object_id ); 459 439 460 // Run the query, will return true if deleted, false otherwise 440 461 $result = (bool) $wpdb->query( $wpdb->prepare( "DELETE FROM $table WHERE $id_column = %d LIMIT 1;", $meta_id ) ); 441 462 … … 448 469 449 470 do_action( "deleted_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value ); 450 471 472 if ( 'post' == $meta_type ) 473 do_action( 'delete_postmeta', $object_id ); 474 451 475 return $result; 452 476 453 477 } -
wp-admin/includes/post.php
701 701 * @return unknown 702 702 */ 703 703 function delete_meta( $mid ) { 704 global $wpdb; 705 $mid = (int) $mid; 706 707 $post_id = $wpdb->get_var( $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_id = %d", $mid) ); 708 709 do_action( 'delete_postmeta', $mid ); 710 wp_cache_delete($post_id, 'post_meta'); 711 $rval = $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_id = %d", $mid) ); 712 do_action( 'deleted_postmeta', $mid ); 713 714 return $rval; 704 return delete_metadata_by_mid( 'post' , $mid); 715 705 } 716 706 717 707 /** … … 742 732 * @return unknown 743 733 */ 744 734 function get_post_meta_by_id( $mid ) { 745 global $wpdb; 746 $mid = (int) $mid; 747 748 $meta = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->postmeta WHERE meta_id = %d", $mid) ); 749 if ( empty($meta) ) 750 return false; 751 if ( is_serialized_string( $meta->meta_value ) ) 752 $meta->meta_value = maybe_unserialize( $meta->meta_value ); 753 return $meta; 735 return get_metadata_by_mid( 'post', $mid ); 754 736 } 755 737 756 738 /** … … 782 764 * @return unknown 783 765 */ 784 766 function update_meta( $meta_id, $meta_key, $meta_value ) { 785 global $wpdb; 786 787 $meta_key = stripslashes($meta_key); 788 789 if ( '' === trim( $meta_value ) ) 790 return false; 791 792 $post_id = $wpdb->get_var( $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_id = %d", $meta_id) ); 793 794 $meta_value = maybe_serialize( stripslashes_deep( $meta_value ) ); 795 $meta_id = (int) $meta_id; 796 797 $data = compact( 'meta_key', 'meta_value' ); 798 $where = compact( 'meta_id' ); 799 800 do_action( 'update_postmeta', $meta_id, $post_id, $meta_key, $meta_value ); 801 $rval = $wpdb->update( $wpdb->postmeta, $data, $where ); 802 wp_cache_delete($post_id, 'post_meta'); 803 do_action( 'updated_postmeta', $meta_id, $post_id, $meta_key, $meta_value ); 804 805 return $rval; 767 return update_metadata_by_mid( 'post', $meta_id, $meta_value, $meta_key ); 806 768 } 807 769 808 770 //