Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

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