Edit File by line
/home/barbar84/www/wp-inclu...
File: meta.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Core Metadata API
[2] Fix | Delete
*
[3] Fix | Delete
* Functions for retrieving and manipulating metadata of various WordPress object types. Metadata
[4] Fix | Delete
* for an object is a represented by a simple key-value pair. Objects may contain multiple
[5] Fix | Delete
* metadata entries that share the same key and differ only in their value.
[6] Fix | Delete
*
[7] Fix | Delete
* @package WordPress
[8] Fix | Delete
* @subpackage Meta
[9] Fix | Delete
*/
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* Adds metadata for the specified object.
[13] Fix | Delete
*
[14] Fix | Delete
* @since 2.9.0
[15] Fix | Delete
*
[16] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[17] Fix | Delete
*
[18] Fix | Delete
* @param string $meta_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
[19] Fix | Delete
* or any other object type with an associated meta table.
[20] Fix | Delete
* @param int $object_id ID of the object metadata is for.
[21] Fix | Delete
* @param string $meta_key Metadata key.
[22] Fix | Delete
* @param mixed $meta_value Metadata value. Must be serializable if non-scalar.
[23] Fix | Delete
* @param bool $unique Optional. Whether the specified metadata key should be unique for the object.
[24] Fix | Delete
* If true, and the object already has a value for the specified metadata key,
[25] Fix | Delete
* no change will be made. Default false.
[26] Fix | Delete
* @return int|false The meta ID on success, false on failure.
[27] Fix | Delete
*/
[28] Fix | Delete
function add_metadata( $meta_type, $object_id, $meta_key, $meta_value, $unique = false ) {
[29] Fix | Delete
global $wpdb;
[30] Fix | Delete
[31] Fix | Delete
if ( ! $meta_type || ! $meta_key || ! is_numeric( $object_id ) ) {
[32] Fix | Delete
return false;
[33] Fix | Delete
}
[34] Fix | Delete
[35] Fix | Delete
$object_id = absint( $object_id );
[36] Fix | Delete
if ( ! $object_id ) {
[37] Fix | Delete
return false;
[38] Fix | Delete
}
[39] Fix | Delete
[40] Fix | Delete
$table = _get_meta_table( $meta_type );
[41] Fix | Delete
if ( ! $table ) {
[42] Fix | Delete
return false;
[43] Fix | Delete
}
[44] Fix | Delete
[45] Fix | Delete
$meta_subtype = get_object_subtype( $meta_type, $object_id );
[46] Fix | Delete
[47] Fix | Delete
$column = sanitize_key( $meta_type . '_id' );
[48] Fix | Delete
[49] Fix | Delete
// expected_slashed ($meta_key)
[50] Fix | Delete
$meta_key = wp_unslash( $meta_key );
[51] Fix | Delete
$meta_value = wp_unslash( $meta_value );
[52] Fix | Delete
$meta_value = sanitize_meta( $meta_key, $meta_value, $meta_type, $meta_subtype );
[53] Fix | Delete
[54] Fix | Delete
/**
[55] Fix | Delete
* Short-circuits adding metadata of a specific type.
[56] Fix | Delete
*
[57] Fix | Delete
* The dynamic portion of the hook, `$meta_type`, refers to the meta object type
[58] Fix | Delete
* (post, comment, term, user, or any other type with an associated meta table).
[59] Fix | Delete
* Returning a non-null value will effectively short-circuit the function.
[60] Fix | Delete
*
[61] Fix | Delete
* @since 3.1.0
[62] Fix | Delete
*
[63] Fix | Delete
* @param null|bool $check Whether to allow adding metadata for the given type.
[64] Fix | Delete
* @param int $object_id ID of the object metadata is for.
[65] Fix | Delete
* @param string $meta_key Metadata key.
[66] Fix | Delete
* @param mixed $meta_value Metadata value. Must be serializable if non-scalar.
[67] Fix | Delete
* @param bool $unique Whether the specified meta key should be unique for the object.
[68] Fix | Delete
*/
[69] Fix | Delete
$check = apply_filters( "add_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $unique );
[70] Fix | Delete
if ( null !== $check ) {
[71] Fix | Delete
return $check;
[72] Fix | Delete
}
[73] Fix | Delete
[74] Fix | Delete
if ( $unique && $wpdb->get_var(
[75] Fix | Delete
$wpdb->prepare(
[76] Fix | Delete
"SELECT COUNT(*) FROM $table WHERE meta_key = %s AND $column = %d",
[77] Fix | Delete
$meta_key,
[78] Fix | Delete
$object_id
[79] Fix | Delete
)
[80] Fix | Delete
) ) {
[81] Fix | Delete
return false;
[82] Fix | Delete
}
[83] Fix | Delete
[84] Fix | Delete
$_meta_value = $meta_value;
[85] Fix | Delete
$meta_value = maybe_serialize( $meta_value );
[86] Fix | Delete
[87] Fix | Delete
/**
[88] Fix | Delete
* Fires immediately before meta of a specific type is added.
[89] Fix | Delete
*
[90] Fix | Delete
* The dynamic portion of the hook, `$meta_type`, refers to the meta object type
[91] Fix | Delete
* (post, comment, term, user, or any other type with an associated meta table).
[92] Fix | Delete
*
[93] Fix | Delete
* @since 3.1.0
[94] Fix | Delete
*
[95] Fix | Delete
* @param int $object_id ID of the object metadata is for.
[96] Fix | Delete
* @param string $meta_key Metadata key.
[97] Fix | Delete
* @param mixed $_meta_value Metadata value. Serialized if non-scalar.
[98] Fix | Delete
*/
[99] Fix | Delete
do_action( "add_{$meta_type}_meta", $object_id, $meta_key, $_meta_value );
[100] Fix | Delete
[101] Fix | Delete
$result = $wpdb->insert(
[102] Fix | Delete
$table,
[103] Fix | Delete
array(
[104] Fix | Delete
$column => $object_id,
[105] Fix | Delete
'meta_key' => $meta_key,
[106] Fix | Delete
'meta_value' => $meta_value,
[107] Fix | Delete
)
[108] Fix | Delete
);
[109] Fix | Delete
[110] Fix | Delete
if ( ! $result ) {
[111] Fix | Delete
return false;
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
$mid = (int) $wpdb->insert_id;
[115] Fix | Delete
[116] Fix | Delete
wp_cache_delete( $object_id, $meta_type . '_meta' );
[117] Fix | Delete
[118] Fix | Delete
/**
[119] Fix | Delete
* Fires immediately after meta of a specific type is added.
[120] Fix | Delete
*
[121] Fix | Delete
* The dynamic portion of the hook, `$meta_type`, refers to the meta object type
[122] Fix | Delete
* (post, comment, term, user, or any other type with an associated meta table).
[123] Fix | Delete
*
[124] Fix | Delete
* @since 2.9.0
[125] Fix | Delete
*
[126] Fix | Delete
* @param int $mid The meta ID after successful update.
[127] Fix | Delete
* @param int $object_id ID of the object metadata is for.
[128] Fix | Delete
* @param string $meta_key Metadata key.
[129] Fix | Delete
* @param mixed $_meta_value Metadata value. Serialized if non-scalar.
[130] Fix | Delete
*/
[131] Fix | Delete
do_action( "added_{$meta_type}_meta", $mid, $object_id, $meta_key, $_meta_value );
[132] Fix | Delete
[133] Fix | Delete
return $mid;
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
/**
[137] Fix | Delete
* Updates metadata for the specified object. If no value already exists for the specified object
[138] Fix | Delete
* ID and metadata key, the metadata will be added.
[139] Fix | Delete
*
[140] Fix | Delete
* @since 2.9.0
[141] Fix | Delete
*
[142] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[143] Fix | Delete
*
[144] Fix | Delete
* @param string $meta_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
[145] Fix | Delete
* or any other object type with an associated meta table.
[146] Fix | Delete
* @param int $object_id ID of the object metadata is for.
[147] Fix | Delete
* @param string $meta_key Metadata key.
[148] Fix | Delete
* @param mixed $meta_value Metadata value. Must be serializable if non-scalar.
[149] Fix | Delete
* @param mixed $prev_value Optional. Previous value to check before updating.
[150] Fix | Delete
* If specified, only update existing metadata entries with
[151] Fix | Delete
* this value. Otherwise, update all entries. Default empty.
[152] Fix | Delete
* @return int|bool The new meta field ID if a field with the given key didn't exist
[153] Fix | Delete
* and was therefore added, true on successful update,
[154] Fix | Delete
* false on failure or if the value passed to the function
[155] Fix | Delete
* is the same as the one that is already in the database.
[156] Fix | Delete
*/
[157] Fix | Delete
function update_metadata( $meta_type, $object_id, $meta_key, $meta_value, $prev_value = '' ) {
[158] Fix | Delete
global $wpdb;
[159] Fix | Delete
[160] Fix | Delete
if ( ! $meta_type || ! $meta_key || ! is_numeric( $object_id ) ) {
[161] Fix | Delete
return false;
[162] Fix | Delete
}
[163] Fix | Delete
[164] Fix | Delete
$object_id = absint( $object_id );
[165] Fix | Delete
if ( ! $object_id ) {
[166] Fix | Delete
return false;
[167] Fix | Delete
}
[168] Fix | Delete
[169] Fix | Delete
$table = _get_meta_table( $meta_type );
[170] Fix | Delete
if ( ! $table ) {
[171] Fix | Delete
return false;
[172] Fix | Delete
}
[173] Fix | Delete
[174] Fix | Delete
$meta_subtype = get_object_subtype( $meta_type, $object_id );
[175] Fix | Delete
[176] Fix | Delete
$column = sanitize_key( $meta_type . '_id' );
[177] Fix | Delete
$id_column = ( 'user' === $meta_type ) ? 'umeta_id' : 'meta_id';
[178] Fix | Delete
[179] Fix | Delete
// expected_slashed ($meta_key)
[180] Fix | Delete
$raw_meta_key = $meta_key;
[181] Fix | Delete
$meta_key = wp_unslash( $meta_key );
[182] Fix | Delete
$passed_value = $meta_value;
[183] Fix | Delete
$meta_value = wp_unslash( $meta_value );
[184] Fix | Delete
$meta_value = sanitize_meta( $meta_key, $meta_value, $meta_type, $meta_subtype );
[185] Fix | Delete
[186] Fix | Delete
/**
[187] Fix | Delete
* Short-circuits updating metadata of a specific type.
[188] Fix | Delete
*
[189] Fix | Delete
* The dynamic portion of the hook, `$meta_type`, refers to the meta object type
[190] Fix | Delete
* (post, comment, term, user, or any other type with an associated meta table).
[191] Fix | Delete
* Returning a non-null value will effectively short-circuit the function.
[192] Fix | Delete
*
[193] Fix | Delete
* @since 3.1.0
[194] Fix | Delete
*
[195] Fix | Delete
* @param null|bool $check Whether to allow updating metadata for the given type.
[196] Fix | Delete
* @param int $object_id ID of the object metadata is for.
[197] Fix | Delete
* @param string $meta_key Metadata key.
[198] Fix | Delete
* @param mixed $meta_value Metadata value. Must be serializable if non-scalar.
[199] Fix | Delete
* @param mixed $prev_value Optional. Previous value to check before updating.
[200] Fix | Delete
* If specified, only update existing metadata entries with
[201] Fix | Delete
* this value. Otherwise, update all entries.
[202] Fix | Delete
*/
[203] Fix | Delete
$check = apply_filters( "update_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $prev_value );
[204] Fix | Delete
if ( null !== $check ) {
[205] Fix | Delete
return (bool) $check;
[206] Fix | Delete
}
[207] Fix | Delete
[208] Fix | Delete
// Compare existing value to new value if no prev value given and the key exists only once.
[209] Fix | Delete
if ( empty( $prev_value ) ) {
[210] Fix | Delete
$old_value = get_metadata_raw( $meta_type, $object_id, $meta_key );
[211] Fix | Delete
if ( is_countable( $old_value ) && count( $old_value ) === 1 ) {
[212] Fix | Delete
if ( $old_value[0] === $meta_value ) {
[213] Fix | Delete
return false;
[214] Fix | Delete
}
[215] Fix | Delete
}
[216] Fix | Delete
}
[217] Fix | Delete
[218] Fix | Delete
$meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT $id_column FROM $table WHERE meta_key = %s AND $column = %d", $meta_key, $object_id ) );
[219] Fix | Delete
if ( empty( $meta_ids ) ) {
[220] Fix | Delete
return add_metadata( $meta_type, $object_id, $raw_meta_key, $passed_value );
[221] Fix | Delete
}
[222] Fix | Delete
[223] Fix | Delete
$_meta_value = $meta_value;
[224] Fix | Delete
$meta_value = maybe_serialize( $meta_value );
[225] Fix | Delete
[226] Fix | Delete
$data = compact( 'meta_value' );
[227] Fix | Delete
$where = array(
[228] Fix | Delete
$column => $object_id,
[229] Fix | Delete
'meta_key' => $meta_key,
[230] Fix | Delete
);
[231] Fix | Delete
[232] Fix | Delete
if ( ! empty( $prev_value ) ) {
[233] Fix | Delete
$prev_value = maybe_serialize( $prev_value );
[234] Fix | Delete
$where['meta_value'] = $prev_value;
[235] Fix | Delete
}
[236] Fix | Delete
[237] Fix | Delete
foreach ( $meta_ids as $meta_id ) {
[238] Fix | Delete
/**
[239] Fix | Delete
* Fires immediately before updating metadata of a specific type.
[240] Fix | Delete
*
[241] Fix | Delete
* The dynamic portion of the hook, `$meta_type`, refers to the meta object type
[242] Fix | Delete
* (post, comment, term, user, or any other type with an associated meta table).
[243] Fix | Delete
*
[244] Fix | Delete
* @since 2.9.0
[245] Fix | Delete
*
[246] Fix | Delete
* @param int $meta_id ID of the metadata entry to update.
[247] Fix | Delete
* @param int $object_id ID of the object metadata is for.
[248] Fix | Delete
* @param string $meta_key Metadata key.
[249] Fix | Delete
* @param mixed $_meta_value Metadata value. Serialized if non-scalar.
[250] Fix | Delete
*/
[251] Fix | Delete
do_action( "update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value );
[252] Fix | Delete
[253] Fix | Delete
if ( 'post' === $meta_type ) {
[254] Fix | Delete
/**
[255] Fix | Delete
* Fires immediately before updating a post's metadata.
[256] Fix | Delete
*
[257] Fix | Delete
* @since 2.9.0
[258] Fix | Delete
*
[259] Fix | Delete
* @param int $meta_id ID of metadata entry to update.
[260] Fix | Delete
* @param int $object_id Post ID.
[261] Fix | Delete
* @param string $meta_key Metadata key.
[262] Fix | Delete
* @param mixed $meta_value Metadata value. This will be a PHP-serialized string representation of the value
[263] Fix | Delete
* if the value is an array, an object, or itself a PHP-serialized string.
[264] Fix | Delete
*/
[265] Fix | Delete
do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value );
[266] Fix | Delete
}
[267] Fix | Delete
}
[268] Fix | Delete
[269] Fix | Delete
$result = $wpdb->update( $table, $data, $where );
[270] Fix | Delete
if ( ! $result ) {
[271] Fix | Delete
return false;
[272] Fix | Delete
}
[273] Fix | Delete
[274] Fix | Delete
wp_cache_delete( $object_id, $meta_type . '_meta' );
[275] Fix | Delete
[276] Fix | Delete
foreach ( $meta_ids as $meta_id ) {
[277] Fix | Delete
/**
[278] Fix | Delete
* Fires immediately after updating metadata of a specific type.
[279] Fix | Delete
*
[280] Fix | Delete
* The dynamic portion of the hook, `$meta_type`, refers to the meta object type
[281] Fix | Delete
* (post, comment, term, user, or any other type with an associated meta table).
[282] Fix | Delete
*
[283] Fix | Delete
* @since 2.9.0
[284] Fix | Delete
*
[285] Fix | Delete
* @param int $meta_id ID of updated metadata entry.
[286] Fix | Delete
* @param int $object_id ID of the object metadata is for.
[287] Fix | Delete
* @param string $meta_key Metadata key.
[288] Fix | Delete
* @param mixed $_meta_value Metadata value. Serialized if non-scalar.
[289] Fix | Delete
*/
[290] Fix | Delete
do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value );
[291] Fix | Delete
[292] Fix | Delete
if ( 'post' === $meta_type ) {
[293] Fix | Delete
/**
[294] Fix | Delete
* Fires immediately after updating a post's metadata.
[295] Fix | Delete
*
[296] Fix | Delete
* @since 2.9.0
[297] Fix | Delete
*
[298] Fix | Delete
* @param int $meta_id ID of updated metadata entry.
[299] Fix | Delete
* @param int $object_id Post ID.
[300] Fix | Delete
* @param string $meta_key Metadata key.
[301] Fix | Delete
* @param mixed $meta_value Metadata value. This will be a PHP-serialized string representation of the value
[302] Fix | Delete
* if the value is an array, an object, or itself a PHP-serialized string.
[303] Fix | Delete
*/
[304] Fix | Delete
do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value );
[305] Fix | Delete
}
[306] Fix | Delete
}
[307] Fix | Delete
[308] Fix | Delete
return true;
[309] Fix | Delete
}
[310] Fix | Delete
[311] Fix | Delete
/**
[312] Fix | Delete
* Deletes metadata for the specified object.
[313] Fix | Delete
*
[314] Fix | Delete
* @since 2.9.0
[315] Fix | Delete
*
[316] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[317] Fix | Delete
*
[318] Fix | Delete
* @param string $meta_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
[319] Fix | Delete
* or any other object type with an associated meta table.
[320] Fix | Delete
* @param int $object_id ID of the object metadata is for.
[321] Fix | Delete
* @param string $meta_key Metadata key.
[322] Fix | Delete
* @param mixed $meta_value Optional. Metadata value. Must be serializable if non-scalar.
[323] Fix | Delete
* If specified, only delete metadata entries with this value.
[324] Fix | Delete
* Otherwise, delete all entries with the specified meta_key.
[325] Fix | Delete
* Pass `null`, `false`, or an empty string to skip this check.
[326] Fix | Delete
* (For backward compatibility, it is not possible to pass an empty string
[327] Fix | Delete
* to delete those entries with an empty string for a value.)
[328] Fix | Delete
* @param bool $delete_all Optional. If true, delete matching metadata entries for all objects,
[329] Fix | Delete
* ignoring the specified object_id. Otherwise, only delete
[330] Fix | Delete
* matching metadata entries for the specified object_id. Default false.
[331] Fix | Delete
* @return bool True on successful delete, false on failure.
[332] Fix | Delete
*/
[333] Fix | Delete
function delete_metadata( $meta_type, $object_id, $meta_key, $meta_value = '', $delete_all = false ) {
[334] Fix | Delete
global $wpdb;
[335] Fix | Delete
[336] Fix | Delete
if ( ! $meta_type || ! $meta_key || ! is_numeric( $object_id ) && ! $delete_all ) {
[337] Fix | Delete
return false;
[338] Fix | Delete
}
[339] Fix | Delete
[340] Fix | Delete
$object_id = absint( $object_id );
[341] Fix | Delete
if ( ! $object_id && ! $delete_all ) {
[342] Fix | Delete
return false;
[343] Fix | Delete
}
[344] Fix | Delete
[345] Fix | Delete
$table = _get_meta_table( $meta_type );
[346] Fix | Delete
if ( ! $table ) {
[347] Fix | Delete
return false;
[348] Fix | Delete
}
[349] Fix | Delete
[350] Fix | Delete
$type_column = sanitize_key( $meta_type . '_id' );
[351] Fix | Delete
$id_column = ( 'user' === $meta_type ) ? 'umeta_id' : 'meta_id';
[352] Fix | Delete
[353] Fix | Delete
// expected_slashed ($meta_key)
[354] Fix | Delete
$meta_key = wp_unslash( $meta_key );
[355] Fix | Delete
$meta_value = wp_unslash( $meta_value );
[356] Fix | Delete
[357] Fix | Delete
/**
[358] Fix | Delete
* Short-circuits deleting metadata of a specific type.
[359] Fix | Delete
*
[360] Fix | Delete
* The dynamic portion of the hook, `$meta_type`, refers to the meta object type
[361] Fix | Delete
* (post, comment, term, user, or any other type with an associated meta table).
[362] Fix | Delete
* Returning a non-null value will effectively short-circuit the function.
[363] Fix | Delete
*
[364] Fix | Delete
* @since 3.1.0
[365] Fix | Delete
*
[366] Fix | Delete
* @param null|bool $delete Whether to allow metadata deletion of the given type.
[367] Fix | Delete
* @param int $object_id ID of the object metadata is for.
[368] Fix | Delete
* @param string $meta_key Metadata key.
[369] Fix | Delete
* @param mixed $meta_value Metadata value. Must be serializable if non-scalar.
[370] Fix | Delete
* @param bool $delete_all Whether to delete the matching metadata entries
[371] Fix | Delete
* for all objects, ignoring the specified $object_id.
[372] Fix | Delete
* Default false.
[373] Fix | Delete
*/
[374] Fix | Delete
$check = apply_filters( "delete_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $delete_all );
[375] Fix | Delete
if ( null !== $check ) {
[376] Fix | Delete
return (bool) $check;
[377] Fix | Delete
}
[378] Fix | Delete
[379] Fix | Delete
$_meta_value = $meta_value;
[380] Fix | Delete
$meta_value = maybe_serialize( $meta_value );
[381] Fix | Delete
[382] Fix | Delete
$query = $wpdb->prepare( "SELECT $id_column FROM $table WHERE meta_key = %s", $meta_key );
[383] Fix | Delete
[384] Fix | Delete
if ( ! $delete_all ) {
[385] Fix | Delete
$query .= $wpdb->prepare( " AND $type_column = %d", $object_id );
[386] Fix | Delete
}
[387] Fix | Delete
[388] Fix | Delete
if ( '' !== $meta_value && null !== $meta_value && false !== $meta_value ) {
[389] Fix | Delete
$query .= $wpdb->prepare( ' AND meta_value = %s', $meta_value );
[390] Fix | Delete
}
[391] Fix | Delete
[392] Fix | Delete
$meta_ids = $wpdb->get_col( $query );
[393] Fix | Delete
if ( ! count( $meta_ids ) ) {
[394] Fix | Delete
return false;
[395] Fix | Delete
}
[396] Fix | Delete
[397] Fix | Delete
if ( $delete_all ) {
[398] Fix | Delete
if ( '' !== $meta_value && null !== $meta_value && false !== $meta_value ) {
[399] Fix | Delete
$object_ids = $wpdb->get_col( $wpdb->prepare( "SELECT $type_column FROM $table WHERE meta_key = %s AND meta_value = %s", $meta_key, $meta_value ) );
[400] Fix | Delete
} else {
[401] Fix | Delete
$object_ids = $wpdb->get_col( $wpdb->prepare( "SELECT $type_column FROM $table WHERE meta_key = %s", $meta_key ) );
[402] Fix | Delete
}
[403] Fix | Delete
}
[404] Fix | Delete
[405] Fix | Delete
/**
[406] Fix | Delete
* Fires immediately before deleting metadata of a specific type.
[407] Fix | Delete
*
[408] Fix | Delete
* The dynamic portion of the hook, `$meta_type`, refers to the meta object type
[409] Fix | Delete
* (post, comment, term, user, or any other type with an associated meta table).
[410] Fix | Delete
*
[411] Fix | Delete
* @since 3.1.0
[412] Fix | Delete
*
[413] Fix | Delete
* @param string[] $meta_ids An array of metadata entry IDs to delete.
[414] Fix | Delete
* @param int $object_id ID of the object metadata is for.
[415] Fix | Delete
* @param string $meta_key Metadata key.
[416] Fix | Delete
* @param mixed $_meta_value Metadata value. Serialized if non-scalar.
[417] Fix | Delete
*/
[418] Fix | Delete
do_action( "delete_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value );
[419] Fix | Delete
[420] Fix | Delete
// Old-style action.
[421] Fix | Delete
if ( 'post' === $meta_type ) {
[422] Fix | Delete
/**
[423] Fix | Delete
* Fires immediately before deleting metadata for a post.
[424] Fix | Delete
*
[425] Fix | Delete
* @since 2.9.0
[426] Fix | Delete
*
[427] Fix | Delete
* @param string[] $meta_ids An array of metadata entry IDs to delete.
[428] Fix | Delete
*/
[429] Fix | Delete
do_action( 'delete_postmeta', $meta_ids );
[430] Fix | Delete
}
[431] Fix | Delete
[432] Fix | Delete
$query = "DELETE FROM $table WHERE $id_column IN( " . implode( ',', $meta_ids ) . ' )';
[433] Fix | Delete
[434] Fix | Delete
$count = $wpdb->query( $query );
[435] Fix | Delete
[436] Fix | Delete
if ( ! $count ) {
[437] Fix | Delete
return false;
[438] Fix | Delete
}
[439] Fix | Delete
[440] Fix | Delete
if ( $delete_all ) {
[441] Fix | Delete
foreach ( (array) $object_ids as $o_id ) {
[442] Fix | Delete
wp_cache_delete( $o_id, $meta_type . '_meta' );
[443] Fix | Delete
}
[444] Fix | Delete
} else {
[445] Fix | Delete
wp_cache_delete( $object_id, $meta_type . '_meta' );
[446] Fix | Delete
}
[447] Fix | Delete
[448] Fix | Delete
/**
[449] Fix | Delete
* Fires immediately after deleting metadata of a specific type.
[450] Fix | Delete
*
[451] Fix | Delete
* The dynamic portion of the hook, `$meta_type`, refers to the meta object type
[452] Fix | Delete
* (post, comment, term, user, or any other type with an associated meta table).
[453] Fix | Delete
*
[454] Fix | Delete
* @since 2.9.0
[455] Fix | Delete
*
[456] Fix | Delete
* @param string[] $meta_ids An array of metadata entry IDs to delete.
[457] Fix | Delete
* @param int $object_id ID of the object metadata is for.
[458] Fix | Delete
* @param string $meta_key Metadata key.
[459] Fix | Delete
* @param mixed $_meta_value Metadata value. Serialized if non-scalar.
[460] Fix | Delete
*/
[461] Fix | Delete
do_action( "deleted_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value );
[462] Fix | Delete
[463] Fix | Delete
// Old-style action.
[464] Fix | Delete
if ( 'post' === $meta_type ) {
[465] Fix | Delete
/**
[466] Fix | Delete
* Fires immediately after deleting metadata for a post.
[467] Fix | Delete
*
[468] Fix | Delete
* @since 2.9.0
[469] Fix | Delete
*
[470] Fix | Delete
* @param string[] $meta_ids An array of metadata entry IDs to delete.
[471] Fix | Delete
*/
[472] Fix | Delete
do_action( 'deleted_postmeta', $meta_ids );
[473] Fix | Delete
}
[474] Fix | Delete
[475] Fix | Delete
return true;
[476] Fix | Delete
}
[477] Fix | Delete
[478] Fix | Delete
/**
[479] Fix | Delete
* Retrieves the value of a metadata field for the specified object type and ID.
[480] Fix | Delete
*
[481] Fix | Delete
* If the meta field exists, a single value is returned if `$single` is true,
[482] Fix | Delete
* or an array of values if it's false.
[483] Fix | Delete
*
[484] Fix | Delete
* If the meta field does not exist, the result depends on get_metadata_default().
[485] Fix | Delete
* By default, an empty string is returned if `$single` is true, or an empty array
[486] Fix | Delete
* if it's false.
[487] Fix | Delete
*
[488] Fix | Delete
* @since 2.9.0
[489] Fix | Delete
*
[490] Fix | Delete
* @see get_metadata_raw()
[491] Fix | Delete
* @see get_metadata_default()
[492] Fix | Delete
*
[493] Fix | Delete
* @param string $meta_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
[494] Fix | Delete
* or any other object type with an associated meta table.
[495] Fix | Delete
* @param int $object_id ID of the object metadata is for.
[496] Fix | Delete
* @param string $meta_key Optional. Metadata key. If not specified, retrieve all metadata for
[497] Fix | Delete
* the specified object. Default empty.
[498] Fix | Delete
* @param bool $single Optional. If true, return only the first value of the specified meta_key.
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function