Fix delete_metadata(), see #2659
git-svn-id: https://develop.svn.wordpress.org/trunk@11996 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
1c12fc9165
commit
f7e5db2645
@ -80,8 +80,8 @@ function update_metadata($meta_type, $object_id, $meta_key, $meta_value, $prev_v
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete_metadata($meta_type, $object_id, $meta_key, $meta_value = '') {
|
function delete_metadata($meta_type, $object_id, $meta_key, $meta_value = '', $delete_all = false) {
|
||||||
if ( !$meta_type || !$meta_key )
|
if ( !$meta_type || !$meta_key || (!$delete_all && ! (int)$object_id) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ( ! $table = _get_meta_table($meta_type) )
|
if ( ! $table = _get_meta_table($meta_type) )
|
||||||
@ -89,16 +89,17 @@ function delete_metadata($meta_type, $object_id, $meta_key, $meta_value = '') {
|
|||||||
|
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
$column = esc_sql($meta_type . '_id');
|
|
||||||
|
|
||||||
// expected_slashed ($meta_key)
|
// expected_slashed ($meta_key)
|
||||||
$meta_key = stripslashes($meta_key);
|
$meta_key = stripslashes($meta_key);
|
||||||
$meta_value = maybe_serialize( stripslashes_deep($meta_value) );
|
$meta_value = maybe_serialize( stripslashes_deep($meta_value) );
|
||||||
|
|
||||||
$query = $wpdb->prepare( "SELECT meta_id FROM $table WHERE meta_key = %s", $meta_key );
|
$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 )
|
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 );
|
$meta_ids = $wpdb->get_col( $query );
|
||||||
if ( !count( $meta_ids ) )
|
if ( !count( $meta_ids ) )
|
||||||
|
Loading…
Reference in New Issue
Block a user