Edit File by line
/home/barbar84/www/wp-inclu...
File: meta.php
*/
[1000] Fix | Delete
function update_meta_cache( $meta_type, $object_ids ) {
[1001] Fix | Delete
global $wpdb;
[1002] Fix | Delete
[1003] Fix | Delete
if ( ! $meta_type || ! $object_ids ) {
[1004] Fix | Delete
return false;
[1005] Fix | Delete
}
[1006] Fix | Delete
[1007] Fix | Delete
$table = _get_meta_table( $meta_type );
[1008] Fix | Delete
if ( ! $table ) {
[1009] Fix | Delete
return false;
[1010] Fix | Delete
}
[1011] Fix | Delete
[1012] Fix | Delete
$column = sanitize_key( $meta_type . '_id' );
[1013] Fix | Delete
[1014] Fix | Delete
if ( ! is_array( $object_ids ) ) {
[1015] Fix | Delete
$object_ids = preg_replace( '|[^0-9,]|', '', $object_ids );
[1016] Fix | Delete
$object_ids = explode( ',', $object_ids );
[1017] Fix | Delete
}
[1018] Fix | Delete
[1019] Fix | Delete
$object_ids = array_map( 'intval', $object_ids );
[1020] Fix | Delete
[1021] Fix | Delete
/**
[1022] Fix | Delete
* Short-circuits updating the metadata cache of a specific type.
[1023] Fix | Delete
*
[1024] Fix | Delete
* The dynamic portion of the hook, `$meta_type`, refers to the meta object type
[1025] Fix | Delete
* (post, comment, term, user, or any other type with an associated meta table).
[1026] Fix | Delete
* Returning a non-null value will effectively short-circuit the function.
[1027] Fix | Delete
*
[1028] Fix | Delete
* @since 5.0.0
[1029] Fix | Delete
*
[1030] Fix | Delete
* @param mixed $check Whether to allow updating the meta cache of the given type.
[1031] Fix | Delete
* @param int[] $object_ids Array of object IDs to update the meta cache for.
[1032] Fix | Delete
*/
[1033] Fix | Delete
$check = apply_filters( "update_{$meta_type}_metadata_cache", null, $object_ids );
[1034] Fix | Delete
if ( null !== $check ) {
[1035] Fix | Delete
return (bool) $check;
[1036] Fix | Delete
}
[1037] Fix | Delete
[1038] Fix | Delete
$cache_key = $meta_type . '_meta';
[1039] Fix | Delete
$non_cached_ids = array();
[1040] Fix | Delete
$cache = array();
[1041] Fix | Delete
$cache_values = wp_cache_get_multiple( $object_ids, $cache_key );
[1042] Fix | Delete
[1043] Fix | Delete
foreach ( $cache_values as $id => $cached_object ) {
[1044] Fix | Delete
if ( false === $cached_object ) {
[1045] Fix | Delete
$non_cached_ids[] = $id;
[1046] Fix | Delete
} else {
[1047] Fix | Delete
$cache[ $id ] = $cached_object;
[1048] Fix | Delete
}
[1049] Fix | Delete
}
[1050] Fix | Delete
[1051] Fix | Delete
if ( empty( $non_cached_ids ) ) {
[1052] Fix | Delete
return $cache;
[1053] Fix | Delete
}
[1054] Fix | Delete
[1055] Fix | Delete
// Get meta info.
[1056] Fix | Delete
$id_list = implode( ',', $non_cached_ids );
[1057] Fix | Delete
$id_column = ( 'user' === $meta_type ) ? 'umeta_id' : 'meta_id';
[1058] Fix | Delete
[1059] Fix | Delete
$meta_list = $wpdb->get_results( "SELECT $column, meta_key, meta_value FROM $table WHERE $column IN ($id_list) ORDER BY $id_column ASC", ARRAY_A );
[1060] Fix | Delete
[1061] Fix | Delete
if ( ! empty( $meta_list ) ) {
[1062] Fix | Delete
foreach ( $meta_list as $metarow ) {
[1063] Fix | Delete
$mpid = (int) $metarow[ $column ];
[1064] Fix | Delete
$mkey = $metarow['meta_key'];
[1065] Fix | Delete
$mval = $metarow['meta_value'];
[1066] Fix | Delete
[1067] Fix | Delete
// Force subkeys to be array type.
[1068] Fix | Delete
if ( ! isset( $cache[ $mpid ] ) || ! is_array( $cache[ $mpid ] ) ) {
[1069] Fix | Delete
$cache[ $mpid ] = array();
[1070] Fix | Delete
}
[1071] Fix | Delete
if ( ! isset( $cache[ $mpid ][ $mkey ] ) || ! is_array( $cache[ $mpid ][ $mkey ] ) ) {
[1072] Fix | Delete
$cache[ $mpid ][ $mkey ] = array();
[1073] Fix | Delete
}
[1074] Fix | Delete
[1075] Fix | Delete
// Add a value to the current pid/key.
[1076] Fix | Delete
$cache[ $mpid ][ $mkey ][] = $mval;
[1077] Fix | Delete
}
[1078] Fix | Delete
}
[1079] Fix | Delete
[1080] Fix | Delete
foreach ( $non_cached_ids as $id ) {
[1081] Fix | Delete
if ( ! isset( $cache[ $id ] ) ) {
[1082] Fix | Delete
$cache[ $id ] = array();
[1083] Fix | Delete
}
[1084] Fix | Delete
wp_cache_add( $id, $cache[ $id ], $cache_key );
[1085] Fix | Delete
}
[1086] Fix | Delete
[1087] Fix | Delete
return $cache;
[1088] Fix | Delete
}
[1089] Fix | Delete
[1090] Fix | Delete
/**
[1091] Fix | Delete
* Retrieves the queue for lazy-loading metadata.
[1092] Fix | Delete
*
[1093] Fix | Delete
* @since 4.5.0
[1094] Fix | Delete
*
[1095] Fix | Delete
* @return WP_Metadata_Lazyloader Metadata lazyloader queue.
[1096] Fix | Delete
*/
[1097] Fix | Delete
function wp_metadata_lazyloader() {
[1098] Fix | Delete
static $wp_metadata_lazyloader;
[1099] Fix | Delete
[1100] Fix | Delete
if ( null === $wp_metadata_lazyloader ) {
[1101] Fix | Delete
$wp_metadata_lazyloader = new WP_Metadata_Lazyloader();
[1102] Fix | Delete
}
[1103] Fix | Delete
[1104] Fix | Delete
return $wp_metadata_lazyloader;
[1105] Fix | Delete
}
[1106] Fix | Delete
[1107] Fix | Delete
/**
[1108] Fix | Delete
* Given a meta query, generates SQL clauses to be appended to a main query.
[1109] Fix | Delete
*
[1110] Fix | Delete
* @since 3.2.0
[1111] Fix | Delete
*
[1112] Fix | Delete
* @see WP_Meta_Query
[1113] Fix | Delete
*
[1114] Fix | Delete
* @param array $meta_query A meta query.
[1115] Fix | Delete
* @param string $type Type of meta.
[1116] Fix | Delete
* @param string $primary_table Primary database table name.
[1117] Fix | Delete
* @param string $primary_id_column Primary ID column name.
[1118] Fix | Delete
* @param object $context Optional. The main query object
[1119] Fix | Delete
* @return array Associative array of `JOIN` and `WHERE` SQL.
[1120] Fix | Delete
*/
[1121] Fix | Delete
function get_meta_sql( $meta_query, $type, $primary_table, $primary_id_column, $context = null ) {
[1122] Fix | Delete
$meta_query_obj = new WP_Meta_Query( $meta_query );
[1123] Fix | Delete
return $meta_query_obj->get_sql( $type, $primary_table, $primary_id_column, $context );
[1124] Fix | Delete
}
[1125] Fix | Delete
[1126] Fix | Delete
/**
[1127] Fix | Delete
* Retrieves the name of the metadata table for the specified object type.
[1128] Fix | Delete
*
[1129] Fix | Delete
* @since 2.9.0
[1130] Fix | Delete
*
[1131] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[1132] Fix | Delete
*
[1133] Fix | Delete
* @param string $type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
[1134] Fix | Delete
* or any other object type with an associated meta table.
[1135] Fix | Delete
* @return string|false Metadata table name, or false if no metadata table exists
[1136] Fix | Delete
*/
[1137] Fix | Delete
function _get_meta_table( $type ) {
[1138] Fix | Delete
global $wpdb;
[1139] Fix | Delete
[1140] Fix | Delete
$table_name = $type . 'meta';
[1141] Fix | Delete
[1142] Fix | Delete
if ( empty( $wpdb->$table_name ) ) {
[1143] Fix | Delete
return false;
[1144] Fix | Delete
}
[1145] Fix | Delete
[1146] Fix | Delete
return $wpdb->$table_name;
[1147] Fix | Delete
}
[1148] Fix | Delete
[1149] Fix | Delete
/**
[1150] Fix | Delete
* Determines whether a meta key is considered protected.
[1151] Fix | Delete
*
[1152] Fix | Delete
* @since 3.1.3
[1153] Fix | Delete
*
[1154] Fix | Delete
* @param string $meta_key Metadata key.
[1155] Fix | Delete
* @param string $meta_type Optional. Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
[1156] Fix | Delete
* or any other object type with an associated meta table. Default empty.
[1157] Fix | Delete
* @return bool Whether the meta key is considered protected.
[1158] Fix | Delete
*/
[1159] Fix | Delete
function is_protected_meta( $meta_key, $meta_type = '' ) {
[1160] Fix | Delete
$sanitized_key = preg_replace( "/[^\x20-\x7E\p{L}]/", '', $meta_key );
[1161] Fix | Delete
$protected = strlen( $sanitized_key ) > 0 && ( '_' === $sanitized_key[0] );
[1162] Fix | Delete
[1163] Fix | Delete
/**
[1164] Fix | Delete
* Filters whether a meta key is considered protected.
[1165] Fix | Delete
*
[1166] Fix | Delete
* @since 3.2.0
[1167] Fix | Delete
*
[1168] Fix | Delete
* @param bool $protected Whether the key is considered protected.
[1169] Fix | Delete
* @param string $meta_key Metadata key.
[1170] Fix | Delete
* @param string $meta_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
[1171] Fix | Delete
* or any other object type with an associated meta table.
[1172] Fix | Delete
*/
[1173] Fix | Delete
return apply_filters( 'is_protected_meta', $protected, $meta_key, $meta_type );
[1174] Fix | Delete
}
[1175] Fix | Delete
[1176] Fix | Delete
/**
[1177] Fix | Delete
* Sanitizes meta value.
[1178] Fix | Delete
*
[1179] Fix | Delete
* @since 3.1.3
[1180] Fix | Delete
* @since 4.9.8 The `$object_subtype` parameter was added.
[1181] Fix | Delete
*
[1182] Fix | Delete
* @param string $meta_key Metadata key.
[1183] Fix | Delete
* @param mixed $meta_value Metadata value to sanitize.
[1184] Fix | Delete
* @param string $object_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
[1185] Fix | Delete
* or any other object type with an associated meta table.
[1186] Fix | Delete
* @param string $object_subtype Optional. The subtype of the object type.
[1187] Fix | Delete
* @return mixed Sanitized $meta_value.
[1188] Fix | Delete
*/
[1189] Fix | Delete
function sanitize_meta( $meta_key, $meta_value, $object_type, $object_subtype = '' ) {
[1190] Fix | Delete
if ( ! empty( $object_subtype ) && has_filter( "sanitize_{$object_type}_meta_{$meta_key}_for_{$object_subtype}" ) ) {
[1191] Fix | Delete
[1192] Fix | Delete
/**
[1193] Fix | Delete
* Filters the sanitization of a specific meta key of a specific meta type and subtype.
[1194] Fix | Delete
*
[1195] Fix | Delete
* The dynamic portions of the hook name, `$object_type`, `$meta_key`,
[1196] Fix | Delete
* and `$object_subtype`, refer to the metadata object type (comment, post, term, or user),
[1197] Fix | Delete
* the meta key value, and the object subtype respectively.
[1198] Fix | Delete
*
[1199] Fix | Delete
* @since 4.9.8
[1200] Fix | Delete
*
[1201] Fix | Delete
* @param mixed $meta_value Metadata value to sanitize.
[1202] Fix | Delete
* @param string $meta_key Metadata key.
[1203] Fix | Delete
* @param string $object_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
[1204] Fix | Delete
* or any other object type with an associated meta table.
[1205] Fix | Delete
* @param string $object_subtype Object subtype.
[1206] Fix | Delete
*/
[1207] Fix | Delete
return apply_filters( "sanitize_{$object_type}_meta_{$meta_key}_for_{$object_subtype}", $meta_value, $meta_key, $object_type, $object_subtype );
[1208] Fix | Delete
}
[1209] Fix | Delete
[1210] Fix | Delete
/**
[1211] Fix | Delete
* Filters the sanitization of a specific meta key of a specific meta type.
[1212] Fix | Delete
*
[1213] Fix | Delete
* The dynamic portions of the hook name, `$meta_type`, and `$meta_key`,
[1214] Fix | Delete
* refer to the metadata object type (comment, post, term, or user) and the meta
[1215] Fix | Delete
* key value, respectively.
[1216] Fix | Delete
*
[1217] Fix | Delete
* @since 3.3.0
[1218] Fix | Delete
*
[1219] Fix | Delete
* @param mixed $meta_value Metadata value to sanitize.
[1220] Fix | Delete
* @param string $meta_key Metadata key.
[1221] Fix | Delete
* @param string $object_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
[1222] Fix | Delete
* or any other object type with an associated meta table.
[1223] Fix | Delete
*/
[1224] Fix | Delete
return apply_filters( "sanitize_{$object_type}_meta_{$meta_key}", $meta_value, $meta_key, $object_type );
[1225] Fix | Delete
}
[1226] Fix | Delete
[1227] Fix | Delete
/**
[1228] Fix | Delete
* Registers a meta key.
[1229] Fix | Delete
*
[1230] Fix | Delete
* It is recommended to register meta keys for a specific combination of object type and object subtype. If passing
[1231] Fix | Delete
* an object subtype is omitted, the meta key will be registered for the entire object type, however it can be partly
[1232] Fix | Delete
* overridden in case a more specific meta key of the same name exists for the same object type and a subtype.
[1233] Fix | Delete
*
[1234] Fix | Delete
* If an object type does not support any subtypes, such as users or comments, you should commonly call this function
[1235] Fix | Delete
* without passing a subtype.
[1236] Fix | Delete
*
[1237] Fix | Delete
* @since 3.3.0
[1238] Fix | Delete
* @since 4.6.0 {@link https://core.trac.wordpress.org/ticket/35658 Modified
[1239] Fix | Delete
* to support an array of data to attach to registered meta keys}. Previous arguments for
[1240] Fix | Delete
* `$sanitize_callback` and `$auth_callback` have been folded into this array.
[1241] Fix | Delete
* @since 4.9.8 The `$object_subtype` argument was added to the arguments array.
[1242] Fix | Delete
* @since 5.3.0 Valid meta types expanded to include "array" and "object".
[1243] Fix | Delete
* @since 5.5.0 The `$default` argument was added to the arguments array.
[1244] Fix | Delete
*
[1245] Fix | Delete
* @param string $object_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
[1246] Fix | Delete
* or any other object type with an associated meta table.
[1247] Fix | Delete
* @param string $meta_key Meta key to register.
[1248] Fix | Delete
* @param array $args {
[1249] Fix | Delete
* Data used to describe the meta key when registered.
[1250] Fix | Delete
*
[1251] Fix | Delete
* @type string $object_subtype A subtype; e.g. if the object type is "post", the post type. If left empty,
[1252] Fix | Delete
* the meta key will be registered on the entire object type. Default empty.
[1253] Fix | Delete
* @type string $type The type of data associated with this meta key.
[1254] Fix | Delete
* Valid values are 'string', 'boolean', 'integer', 'number', 'array', and 'object'.
[1255] Fix | Delete
* @type string $description A description of the data attached to this meta key.
[1256] Fix | Delete
* @type bool $single Whether the meta key has one value per object, or an array of values per object.
[1257] Fix | Delete
* @type mixed $default The default value returned from get_metadata() if no value has been set yet.
[1258] Fix | Delete
* When using a non-single meta key, the default value is for the first entry.
[1259] Fix | Delete
* In other words, when calling get_metadata() with `$single` set to `false`,
[1260] Fix | Delete
* the default value given here will be wrapped in an array.
[1261] Fix | Delete
* @type callable $sanitize_callback A function or method to call when sanitizing `$meta_key` data.
[1262] Fix | Delete
* @type callable $auth_callback Optional. A function or method to call when performing edit_post_meta,
[1263] Fix | Delete
* add_post_meta, and delete_post_meta capability checks.
[1264] Fix | Delete
* @type bool|array $show_in_rest Whether data associated with this meta key can be considered public and
[1265] Fix | Delete
* should be accessible via the REST API. A custom post type must also declare
[1266] Fix | Delete
* support for custom fields for registered meta to be accessible via REST.
[1267] Fix | Delete
* When registering complex meta values this argument may optionally be an
[1268] Fix | Delete
* array with 'schema' or 'prepare_callback' keys instead of a boolean.
[1269] Fix | Delete
* }
[1270] Fix | Delete
* @param string|array $deprecated Deprecated. Use `$args` instead.
[1271] Fix | Delete
* @return bool True if the meta key was successfully registered in the global array, false if not.
[1272] Fix | Delete
* Registering a meta key with distinct sanitize and auth callbacks will fire those callbacks,
[1273] Fix | Delete
* but will not add to the global registry.
[1274] Fix | Delete
*/
[1275] Fix | Delete
function register_meta( $object_type, $meta_key, $args, $deprecated = null ) {
[1276] Fix | Delete
global $wp_meta_keys;
[1277] Fix | Delete
[1278] Fix | Delete
if ( ! is_array( $wp_meta_keys ) ) {
[1279] Fix | Delete
$wp_meta_keys = array();
[1280] Fix | Delete
}
[1281] Fix | Delete
[1282] Fix | Delete
$defaults = array(
[1283] Fix | Delete
'object_subtype' => '',
[1284] Fix | Delete
'type' => 'string',
[1285] Fix | Delete
'description' => '',
[1286] Fix | Delete
'default' => '',
[1287] Fix | Delete
'single' => false,
[1288] Fix | Delete
'sanitize_callback' => null,
[1289] Fix | Delete
'auth_callback' => null,
[1290] Fix | Delete
'show_in_rest' => false,
[1291] Fix | Delete
);
[1292] Fix | Delete
[1293] Fix | Delete
// There used to be individual args for sanitize and auth callbacks.
[1294] Fix | Delete
$has_old_sanitize_cb = false;
[1295] Fix | Delete
$has_old_auth_cb = false;
[1296] Fix | Delete
[1297] Fix | Delete
if ( is_callable( $args ) ) {
[1298] Fix | Delete
$args = array(
[1299] Fix | Delete
'sanitize_callback' => $args,
[1300] Fix | Delete
);
[1301] Fix | Delete
[1302] Fix | Delete
$has_old_sanitize_cb = true;
[1303] Fix | Delete
} else {
[1304] Fix | Delete
$args = (array) $args;
[1305] Fix | Delete
}
[1306] Fix | Delete
[1307] Fix | Delete
if ( is_callable( $deprecated ) ) {
[1308] Fix | Delete
$args['auth_callback'] = $deprecated;
[1309] Fix | Delete
$has_old_auth_cb = true;
[1310] Fix | Delete
}
[1311] Fix | Delete
[1312] Fix | Delete
/**
[1313] Fix | Delete
* Filters the registration arguments when registering meta.
[1314] Fix | Delete
*
[1315] Fix | Delete
* @since 4.6.0
[1316] Fix | Delete
*
[1317] Fix | Delete
* @param array $args Array of meta registration arguments.
[1318] Fix | Delete
* @param array $defaults Array of default arguments.
[1319] Fix | Delete
* @param string $object_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
[1320] Fix | Delete
* or any other object type with an associated meta table.
[1321] Fix | Delete
* @param string $meta_key Meta key.
[1322] Fix | Delete
*/
[1323] Fix | Delete
$args = apply_filters( 'register_meta_args', $args, $defaults, $object_type, $meta_key );
[1324] Fix | Delete
unset( $defaults['default'] );
[1325] Fix | Delete
$args = wp_parse_args( $args, $defaults );
[1326] Fix | Delete
[1327] Fix | Delete
// Require an item schema when registering array meta.
[1328] Fix | Delete
if ( false !== $args['show_in_rest'] && 'array' === $args['type'] ) {
[1329] Fix | Delete
if ( ! is_array( $args['show_in_rest'] ) || ! isset( $args['show_in_rest']['schema']['items'] ) ) {
[1330] Fix | Delete
_doing_it_wrong( __FUNCTION__, __( 'When registering an "array" meta type to show in the REST API, you must specify the schema for each array item in "show_in_rest.schema.items".' ), '5.3.0' );
[1331] Fix | Delete
[1332] Fix | Delete
return false;
[1333] Fix | Delete
}
[1334] Fix | Delete
}
[1335] Fix | Delete
[1336] Fix | Delete
$object_subtype = ! empty( $args['object_subtype'] ) ? $args['object_subtype'] : '';
[1337] Fix | Delete
[1338] Fix | Delete
// If `auth_callback` is not provided, fall back to `is_protected_meta()`.
[1339] Fix | Delete
if ( empty( $args['auth_callback'] ) ) {
[1340] Fix | Delete
if ( is_protected_meta( $meta_key, $object_type ) ) {
[1341] Fix | Delete
$args['auth_callback'] = '__return_false';
[1342] Fix | Delete
} else {
[1343] Fix | Delete
$args['auth_callback'] = '__return_true';
[1344] Fix | Delete
}
[1345] Fix | Delete
}
[1346] Fix | Delete
[1347] Fix | Delete
// Back-compat: old sanitize and auth callbacks are applied to all of an object type.
[1348] Fix | Delete
if ( is_callable( $args['sanitize_callback'] ) ) {
[1349] Fix | Delete
if ( ! empty( $object_subtype ) ) {
[1350] Fix | Delete
add_filter( "sanitize_{$object_type}_meta_{$meta_key}_for_{$object_subtype}", $args['sanitize_callback'], 10, 4 );
[1351] Fix | Delete
} else {
[1352] Fix | Delete
add_filter( "sanitize_{$object_type}_meta_{$meta_key}", $args['sanitize_callback'], 10, 3 );
[1353] Fix | Delete
}
[1354] Fix | Delete
}
[1355] Fix | Delete
[1356] Fix | Delete
if ( is_callable( $args['auth_callback'] ) ) {
[1357] Fix | Delete
if ( ! empty( $object_subtype ) ) {
[1358] Fix | Delete
add_filter( "auth_{$object_type}_meta_{$meta_key}_for_{$object_subtype}", $args['auth_callback'], 10, 6 );
[1359] Fix | Delete
} else {
[1360] Fix | Delete
add_filter( "auth_{$object_type}_meta_{$meta_key}", $args['auth_callback'], 10, 6 );
[1361] Fix | Delete
}
[1362] Fix | Delete
}
[1363] Fix | Delete
[1364] Fix | Delete
if ( array_key_exists( 'default', $args ) ) {
[1365] Fix | Delete
$schema = $args;
[1366] Fix | Delete
if ( is_array( $args['show_in_rest'] ) && isset( $args['show_in_rest']['schema'] ) ) {
[1367] Fix | Delete
$schema = array_merge( $schema, $args['show_in_rest']['schema'] );
[1368] Fix | Delete
}
[1369] Fix | Delete
[1370] Fix | Delete
$check = rest_validate_value_from_schema( $args['default'], $schema );
[1371] Fix | Delete
if ( is_wp_error( $check ) ) {
[1372] Fix | Delete
_doing_it_wrong( __FUNCTION__, __( 'When registering a default meta value the data must match the type provided.' ), '5.5.0' );
[1373] Fix | Delete
[1374] Fix | Delete
return false;
[1375] Fix | Delete
}
[1376] Fix | Delete
[1377] Fix | Delete
if ( ! has_filter( "default_{$object_type}_metadata", 'filter_default_metadata' ) ) {
[1378] Fix | Delete
add_filter( "default_{$object_type}_metadata", 'filter_default_metadata', 10, 5 );
[1379] Fix | Delete
}
[1380] Fix | Delete
}
[1381] Fix | Delete
[1382] Fix | Delete
// Global registry only contains meta keys registered with the array of arguments added in 4.6.0.
[1383] Fix | Delete
if ( ! $has_old_auth_cb && ! $has_old_sanitize_cb ) {
[1384] Fix | Delete
unset( $args['object_subtype'] );
[1385] Fix | Delete
[1386] Fix | Delete
$wp_meta_keys[ $object_type ][ $object_subtype ][ $meta_key ] = $args;
[1387] Fix | Delete
[1388] Fix | Delete
return true;
[1389] Fix | Delete
}
[1390] Fix | Delete
[1391] Fix | Delete
return false;
[1392] Fix | Delete
}
[1393] Fix | Delete
[1394] Fix | Delete
/**
[1395] Fix | Delete
* Filters into default_{$object_type}_metadata and adds in default value.
[1396] Fix | Delete
*
[1397] Fix | Delete
* @since 5.5.0
[1398] Fix | Delete
*
[1399] Fix | Delete
* @param mixed $value Current value passed to filter.
[1400] Fix | Delete
* @param int $object_id ID of the object metadata is for.
[1401] Fix | Delete
* @param string $meta_key Metadata key.
[1402] Fix | Delete
* @param bool $single If true, return only the first value of the specified meta_key.
[1403] Fix | Delete
* This parameter has no effect if meta_key is not specified.
[1404] Fix | Delete
* @param string $meta_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
[1405] Fix | Delete
* or any other object type with an associated meta table.
[1406] Fix | Delete
* @return mixed Single metadata default, or array of defaults.
[1407] Fix | Delete
*/
[1408] Fix | Delete
function filter_default_metadata( $value, $object_id, $meta_key, $single, $meta_type ) {
[1409] Fix | Delete
global $wp_meta_keys;
[1410] Fix | Delete
[1411] Fix | Delete
if ( wp_installing() ) {
[1412] Fix | Delete
return $value;
[1413] Fix | Delete
}
[1414] Fix | Delete
[1415] Fix | Delete
if ( ! is_array( $wp_meta_keys ) || ! isset( $wp_meta_keys[ $meta_type ] ) ) {
[1416] Fix | Delete
return $value;
[1417] Fix | Delete
}
[1418] Fix | Delete
[1419] Fix | Delete
$defaults = array();
[1420] Fix | Delete
foreach ( $wp_meta_keys[ $meta_type ] as $sub_type => $meta_data ) {
[1421] Fix | Delete
foreach ( $meta_data as $_meta_key => $args ) {
[1422] Fix | Delete
if ( $_meta_key === $meta_key && array_key_exists( 'default', $args ) ) {
[1423] Fix | Delete
$defaults[ $sub_type ] = $args;
[1424] Fix | Delete
}
[1425] Fix | Delete
}
[1426] Fix | Delete
}
[1427] Fix | Delete
[1428] Fix | Delete
if ( ! $defaults ) {
[1429] Fix | Delete
return $value;
[1430] Fix | Delete
}
[1431] Fix | Delete
[1432] Fix | Delete
// If this meta type does not have subtypes, then the default is keyed as an empty string.
[1433] Fix | Delete
if ( isset( $defaults[''] ) ) {
[1434] Fix | Delete
$metadata = $defaults[''];
[1435] Fix | Delete
} else {
[1436] Fix | Delete
$sub_type = get_object_subtype( $meta_type, $object_id );
[1437] Fix | Delete
if ( ! isset( $defaults[ $sub_type ] ) ) {
[1438] Fix | Delete
return $value;
[1439] Fix | Delete
}
[1440] Fix | Delete
$metadata = $defaults[ $sub_type ];
[1441] Fix | Delete
}
[1442] Fix | Delete
[1443] Fix | Delete
if ( $single ) {
[1444] Fix | Delete
$value = $metadata['default'];
[1445] Fix | Delete
} else {
[1446] Fix | Delete
$value = array( $metadata['default'] );
[1447] Fix | Delete
}
[1448] Fix | Delete
[1449] Fix | Delete
return $value;
[1450] Fix | Delete
}
[1451] Fix | Delete
[1452] Fix | Delete
/**
[1453] Fix | Delete
* Checks if a meta key is registered.
[1454] Fix | Delete
*
[1455] Fix | Delete
* @since 4.6.0
[1456] Fix | Delete
* @since 4.9.8 The `$object_subtype` parameter was added.
[1457] Fix | Delete
*
[1458] Fix | Delete
* @param string $object_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
[1459] Fix | Delete
* or any other object type with an associated meta table.
[1460] Fix | Delete
* @param string $meta_key Metadata key.
[1461] Fix | Delete
* @param string $object_subtype Optional. The subtype of the object type.
[1462] Fix | Delete
* @return bool True if the meta key is registered to the object type and, if provided,
[1463] Fix | Delete
* the object subtype. False if not.
[1464] Fix | Delete
*/
[1465] Fix | Delete
function registered_meta_key_exists( $object_type, $meta_key, $object_subtype = '' ) {
[1466] Fix | Delete
$meta_keys = get_registered_meta_keys( $object_type, $object_subtype );
[1467] Fix | Delete
[1468] Fix | Delete
return isset( $meta_keys[ $meta_key ] );
[1469] Fix | Delete
}
[1470] Fix | Delete
[1471] Fix | Delete
/**
[1472] Fix | Delete
* Unregisters a meta key from the list of registered keys.
[1473] Fix | Delete
*
[1474] Fix | Delete
* @since 4.6.0
[1475] Fix | Delete
* @since 4.9.8 The `$object_subtype` parameter was added.
[1476] Fix | Delete
*
[1477] Fix | Delete
* @param string $object_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
[1478] Fix | Delete
* or any other object type with an associated meta table.
[1479] Fix | Delete
* @param string $meta_key Metadata key.
[1480] Fix | Delete
* @param string $object_subtype Optional. The subtype of the object type.
[1481] Fix | Delete
* @return bool True if successful. False if the meta key was not registered.
[1482] Fix | Delete
*/
[1483] Fix | Delete
function unregister_meta_key( $object_type, $meta_key, $object_subtype = '' ) {
[1484] Fix | Delete
global $wp_meta_keys;
[1485] Fix | Delete
[1486] Fix | Delete
if ( ! registered_meta_key_exists( $object_type, $meta_key, $object_subtype ) ) {
[1487] Fix | Delete
return false;
[1488] Fix | Delete
}
[1489] Fix | Delete
[1490] Fix | Delete
$args = $wp_meta_keys[ $object_type ][ $object_subtype ][ $meta_key ];
[1491] Fix | Delete
[1492] Fix | Delete
if ( isset( $args['sanitize_callback'] ) && is_callable( $args['sanitize_callback'] ) ) {
[1493] Fix | Delete
if ( ! empty( $object_subtype ) ) {
[1494] Fix | Delete
remove_filter( "sanitize_{$object_type}_meta_{$meta_key}_for_{$object_subtype}", $args['sanitize_callback'] );
[1495] Fix | Delete
} else {
[1496] Fix | Delete
remove_filter( "sanitize_{$object_type}_meta_{$meta_key}", $args['sanitize_callback'] );
[1497] Fix | Delete
}
[1498] Fix | Delete
}
[1499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function