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:
parent
4e4d7ec08c
commit
5680630d1f
|
@ -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,16 +89,17 @@ 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 );
|
||||
$query .= $wpdb->prepare(" AND meta_value = %s", $meta_value );
|
||||
|
||||
$meta_ids = $wpdb->get_col( $query );
|
||||
if ( !count( $meta_ids ) )
|
||||
|
|
Loading…
Reference in New Issue