Fix delete_metadata(), see #2659

git-svn-id: http://svn.automattic.com/wordpress/trunk@11996 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
azaozz 2009-10-05 01:08:06 +00:00
parent 4e4d7ec08c
commit 5680630d1f
1 changed files with 6 additions and 5 deletions

View File

@ -80,8 +80,8 @@ function update_metadata($meta_type, $object_id, $meta_key, $meta_value, $prev_v
return true;
}
function delete_metadata($meta_type, $object_id, $meta_key, $meta_value = '') {
if ( !$meta_type || !$meta_key )
function delete_metadata($meta_type, $object_id, $meta_key, $meta_value = '', $delete_all = false) {
if ( !$meta_type || !$meta_key || (!$delete_all && ! (int)$object_id) )
return false;
if ( ! $table = _get_meta_table($meta_type) )
@ -89,14 +89,15 @@ function delete_metadata($meta_type, $object_id, $meta_key, $meta_value = '') {
global $wpdb;
$column = esc_sql($meta_type . '_id');
// expected_slashed ($meta_key)
$meta_key = stripslashes($meta_key);
$meta_value = maybe_serialize( stripslashes_deep($meta_value) );
$query = $wpdb->prepare( "SELECT meta_id FROM $table WHERE meta_key = %s", $meta_key );
if ( !$delete_all )
$query .= $wpdb->prepare(" AND %s = %d", $meta_type . '_id', $object_id );
if ( $meta_value )
$query .= $wpdb->prepare(" AND meta_value = %s", $meta_value );