Changeset 47390
- Timestamp:
- 02/28/2020 12:12:58 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/meta.php
r47122 r47390 12 12 13 13 /** 14 * Add metadata for the specified object.14 * Adds metadata for the specified object. 15 15 * 16 16 * @since 2.9.0 … … 18 18 * @global wpdb $wpdb WordPress database abstraction object. 19 19 * 20 * @param string $meta_type Type of object metadata is for (e.g., comment, post, term, or user). 21 * @param int $object_id ID of the object metadata is for 22 * @param string $meta_key Metadata key 20 * @param string $meta_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', 21 * or any other object type with an associated meta table. 22 * @param int $object_id ID of the object metadata is for. 23 * @param string $meta_key Metadata key. 23 24 * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. 24 * @param bool $unique Optional, default is false. 25 * Whether the specified metadata key should be unique for the object. 25 * @param bool $unique Optional. Whether the specified metadata key should be unique for the object. 26 26 * If true, and the object already has a value for the specified metadata key, 27 * no change will be made. 27 * no change will be made. Default false. 28 28 * @return int|false The meta ID on success, false on failure. 29 29 */ … … 64 64 * 65 65 * @param null|bool $check Whether to allow adding metadata for the given type. 66 * @param int $object_id Object ID. 67 * @param string $meta_key Meta key. 68 * @param mixed $meta_value Meta value. Must be serializable if non-scalar. 69 * @param bool $unique Whether the specified meta key should be unique 70 * for the object. Optional. Default false. 66 * @param int $object_id ID of the object metadata is for. 67 * @param string $meta_key Metadata key. 68 * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. 69 * @param bool $unique Whether the specified meta key should be unique for the object. 71 70 */ 72 71 $check = apply_filters( "add_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $unique ); … … 96 95 * @since 3.1.0 97 96 * 98 * @param int $object_id Object ID.99 * @param string $meta_key Meta key.100 * @param mixed $_meta_value Meta value.97 * @param int $object_id ID of the object metadata is for. 98 * @param string $meta_key Metadata key. 99 * @param mixed $_meta_value Metadata value. Serialized if non-scalar. 101 100 */ 102 101 do_action( "add_{$meta_type}_meta", $object_id, $meta_key, $_meta_value ); … … 128 127 * 129 128 * @param int $mid The meta ID after successful update. 130 * @param int $object_id Object ID.131 * @param string $meta_key Meta key.132 * @param mixed $_meta_value Meta value.129 * @param int $object_id ID of the object metadata is for. 130 * @param string $meta_key Metadata key. 131 * @param mixed $_meta_value Metadata value. Serialized if non-scalar. 133 132 */ 134 133 do_action( "added_{$meta_type}_meta", $mid, $object_id, $meta_key, $_meta_value ); … … 138 137 139 138 /** 140 * Update metadata for the specified object. If no value already exists for the specified object139 * Updates metadata for the specified object. If no value already exists for the specified object 141 140 * ID and metadata key, the metadata will be added. 142 141 * … … 145 144 * @global wpdb $wpdb WordPress database abstraction object. 146 145 * 147 * @param string $meta_type Type of object metadata is for (e.g., comment, post, term, or user). 148 * @param int $object_id ID of the object metadata is for 149 * @param string $meta_key Metadata key 146 * @param string $meta_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', 147 * or any other object type with an associated meta table. 148 * @param int $object_id ID of the object metadata is for. 149 * @param string $meta_key Metadata key. 150 150 * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. 151 * @param mixed $prev_value Optional. If specified, only update existing metadata entries with152 * the specifiedvalue. Otherwise, update all entries.151 * @param mixed $prev_value Optional. If specified, only update existing metadata entries 152 * with this value. Otherwise, update all entries. 153 153 * @return int|bool The new meta field ID if a field with the given key didn't exist and was 154 154 * therefore added, true on successful update, false on failure. … … 193 193 * 194 194 * @param null|bool $check Whether to allow updating metadata for the given type. 195 * @param int $object_id Object ID. 196 * @param string $meta_key Meta key. 197 * @param mixed $meta_value Meta value. Must be serializable if non-scalar. 198 * @param mixed $prev_value Optional. If specified, only update existing 199 * metadata entries with the specified value. 200 * Otherwise, update all entries. 195 * @param int $object_id ID of the object metadata is for. 196 * @param string $meta_key Metadata key. 197 * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. 198 * @param mixed $prev_value Optional. If specified, only update existing metadata entries 199 * with this value. Otherwise, update all entries. 201 200 */ 202 201 $check = apply_filters( "update_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $prev_value ); … … 244 243 * 245 244 * @param int $meta_id ID of the metadata entry to update. 246 * @param int $object_id Object ID.247 * @param string $meta_key Meta key.248 * @param mixed $_meta_value Meta value.245 * @param int $object_id ID of the object metadata is for. 246 * @param string $meta_key Metadata key. 247 * @param mixed $_meta_value Metadata value. Serialized if non-scalar. 249 248 */ 250 249 do_action( "update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value ); … … 258 257 * @param int $meta_id ID of metadata entry to update. 259 258 * @param int $object_id Post ID. 260 * @param string $meta_key Meta key.261 * @param mixed $meta_value Meta value. This will be a PHP-serialized string representation of the value if262 * the value is an array, an object, or itself a PHP-serialized string.259 * @param string $meta_key Metadata key. 260 * @param mixed $meta_value Metadata value. This will be a PHP-serialized string representation of the value 261 * if the value is an array, an object, or itself a PHP-serialized string. 263 262 */ 264 263 do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); … … 283 282 * 284 283 * @param int $meta_id ID of updated metadata entry. 285 * @param int $object_id Object ID.286 * @param string $meta_key Meta key.287 * @param mixed $_meta_value Meta value.284 * @param int $object_id ID of the object metadata is for. 285 * @param string $meta_key Metadata key. 286 * @param mixed $_meta_value Metadata value. Serialized if non-scalar. 288 287 */ 289 288 do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value ); … … 297 296 * @param int $meta_id ID of updated metadata entry. 298 297 * @param int $object_id Post ID. 299 * @param string $meta_key Meta key.300 * @param mixed $meta_value Meta value. This will be a PHP-serialized string representation of the value if301 * the value is an array, an object, or itself a PHP-serialized string.298 * @param string $meta_key Metadata key. 299 * @param mixed $meta_value Metadata value. This will be a PHP-serialized string representation of the value 300 * if the value is an array, an object, or itself a PHP-serialized string. 302 301 */ 303 302 do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); … … 309 308 310 309 /** 311 * Delete metadata for the specified object.310 * Deletes metadata for the specified object. 312 311 * 313 312 * @since 2.9.0 … … 315 314 * @global wpdb $wpdb WordPress database abstraction object. 316 315 * 317 * @param string $meta_type Type of object metadata is for (e.g., comment, post, term, or user). 318 * @param int $object_id ID of the object metadata is for 319 * @param string $meta_key Metadata key 320 * @param mixed $meta_value Optional. Metadata value. Must be serializable if non-scalar. If specified, only delete 321 * metadata entries with this value. Otherwise, delete all entries with the specified meta_key. 322 * Pass `null`, `false`, or an empty string to skip this check. (For backward compatibility, 323 * it is not possible to pass an empty string to delete those entries with an empty string 324 * for a value.) 325 * @param bool $delete_all Optional, default is false. If true, delete matching metadata entries for all objects, 326 * ignoring the specified object_id. Otherwise, only delete matching metadata entries for 327 * the specified object_id. 316 * @param string $meta_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', 317 * or any other object type with an associated meta table. 318 * @param int $object_id ID of the object metadata is for. 319 * @param string $meta_key Metadata key. 320 * @param mixed $meta_value Optional. Metadata value. Must be serializable if non-scalar. 321 * If specified, only delete metadata entries with this value. 322 * Otherwise, delete all entries with the specified meta_key. 323 * Pass `null`, `false`, or an empty string to skip this check. 324 * (For backward compatibility, it is not possible to pass an empty string 325 * to delete those entries with an empty string for a value.) 326 * @param bool $delete_all Optional. If true, delete matching metadata entries for all objects, 327 * ignoring the specified object_id. Otherwise, only delete 328 * matching metadata entries for the specified object_id. Default false. 328 329 * @return bool True on successful delete, false on failure. 329 330 */ … … 361 362 * 362 363 * @param null|bool $delete Whether to allow metadata deletion of the given type. 363 * @param int $object_id Object ID.364 * @param string $meta_key Meta key.365 * @param mixed $meta_value Meta value. Must be serializable if non-scalar.364 * @param int $object_id ID of the object metadata is for. 365 * @param string $meta_key Metadata key. 366 * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. 366 367 * @param bool $delete_all Whether to delete the matching metadata entries 367 368 * for all objects, ignoring the specified $object_id. … … 408 409 * 409 410 * @param string[] $meta_ids An array of metadata entry IDs to delete. 410 * @param int $object_id Object ID.411 * @param string $meta_key Meta key.412 * @param mixed $_meta_value Meta value.411 * @param int $object_id ID of the object metadata is for. 412 * @param string $meta_key Metadata key. 413 * @param mixed $_meta_value Metadata value. Serialized if non-scalar. 413 414 */ 414 415 do_action( "delete_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value ); … … 451 452 * 452 453 * @param string[] $meta_ids An array of metadata entry IDs to delete. 453 * @param int $object_id Object ID.454 * @param string $meta_key Meta key.455 * @param mixed $_meta_value Meta value.454 * @param int $object_id ID of the object metadata is for. 455 * @param string $meta_key Metadata key. 456 * @param mixed $_meta_value Metadata value. Serialized if non-scalar. 456 457 */ 457 458 do_action( "deleted_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value ); … … 473 474 474 475 /** 475 * Retrieve metadata for the specified object.476 * Retrieves metadata for the specified object. 476 477 * 477 478 * @since 2.9.0 478 479 * 479 * @param string $meta_type Type of object metadata is for (e.g., comment, post, term, or user). 480 * @param int $object_id ID of the object metadata is for 480 * @param string $meta_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', 481 * or any other object type with an associated meta table. 482 * @param int $object_id ID of the object metadata is for. 481 483 * @param string $meta_key Optional. Metadata key. If not specified, retrieve all metadata for 482 * the specified object. 483 * @param bool $single Optional, default is false. 484 * If true, return only the first value of the specified meta_key. 485 * This parameter has no effect if meta_key is not specified. 484 * the specified object. Default empty. 485 * @param bool $single Optional. If true, return only the first value of the specified meta_key. 486 * This parameter has no effect if meta_key is not specified. Default false. 486 487 * @return mixed Single metadata value, or array of values 487 488 */ … … 507 508 * @param null|array|string $value The value get_metadata() should return - a single metadata value, 508 509 * or an array of values. 509 * @param int $object_id Object ID.510 * @param string $meta_key Meta key.510 * @param int $object_id ID of the object metadata is for. 511 * @param string $meta_key Metadata key. 511 512 * @param bool $single Whether to return only the first value of the specified $meta_key. 512 513 */ … … 551 552 552 553 /** 553 * Determine if a meta key is set for a given object554 * Determines if a meta key is set for a given object. 554 555 * 555 556 * @since 3.3.0 556 557 * 557 * @param string $meta_type Type of object metadata is for (e.g., comment, post, term, or user). 558 * @param int $object_id ID of the object metadata is for 558 * @param string $meta_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', 559 * or any other object type with an associated meta table. 560 * @param int $object_id ID of the object metadata is for. 559 561 * @param string $meta_key Metadata key. 560 562 * @return bool True of the key is set, false if not. … … 591 593 592 594 /** 593 * Get meta data by meta ID595 * Retrieves metadata by meta ID. 594 596 * 595 597 * @since 3.3.0 … … 597 599 * @global wpdb $wpdb WordPress database abstraction object. 598 600 * 599 * @param string $meta_type Type of object metadata is for (e.g., comment, post, term, or user). 600 * @param int $meta_id ID for a specific meta row 601 * @param string $meta_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', 602 * or any other object type with an associated meta table. 603 * @param int $meta_id ID for a specific meta row. 601 604 * @return object|false Meta object or false. 602 605 */ … … 651 654 652 655 /** 653 * Update meta data by meta ID656 * Updates metadata by meta ID. 654 657 * 655 658 * @since 3.3.0 … … 657 660 * @global wpdb $wpdb WordPress database abstraction object. 658 661 * 659 * @param string $meta_type Type of object metadata is for (e.g., comment, post, term, or user). 660 * @param int $meta_id ID for a specific meta row 661 * @param string $meta_value Metadata value 662 * @param string $meta_key Optional, you can provide a meta key to update it 662 * @param string $meta_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', 663 * or any other object type with an associated meta table. 664 * @param int $meta_id ID for a specific meta row. 665 * @param string $meta_value Metadata value. 666 * @param string $meta_key Optional. You can provide a meta key to update it. Default false. 663 667 * @return bool True on successful update, false on failure. 664 668 */ … … 767 771 768 772 /** 769 * Delete meta data by meta ID773 * Deletes metadata by meta ID. 770 774 * 771 775 * @since 3.3.0 … … 773 777 * @global wpdb $wpdb WordPress database abstraction object. 774 778 * 775 * @param string $meta_type Type of object metadata is for (e.g., comment, post, term, or user). 776 * @param int $meta_id ID for a specific meta row 779 * @param string $meta_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', 780 * or any other object type with an associated meta table. 781 * @param int $meta_id ID for a specific meta row. 777 782 * @return bool True on successful delete, false on failure. 778 783 */ … … 872 877 873 878 /** 874 * Update the metadata cache for the specified objects.879 * Updates the metadata cache for the specified objects. 875 880 * 876 881 * @since 2.9.0 … … 878 883 * @global wpdb $wpdb WordPress database abstraction object. 879 884 * 880 * @param string $meta_type Type of object metadata is for (e.g., comment, post, term, or user). 885 * @param string $meta_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', 886 * or any other object type with an associated meta table. 881 887 * @param string|int[] $object_ids Array or comma delimited list of object IDs to update cache for. 882 888 * @return array|false Metadata cache for the specified objects, or false on failure. … … 1007 1013 1008 1014 /** 1009 * Retrieve the name of the metadata table for the specified object type.1015 * Retrieves the name of the metadata table for the specified object type. 1010 1016 * 1011 1017 * @since 2.9.0 … … 1013 1019 * @global wpdb $wpdb WordPress database abstraction object. 1014 1020 * 1015 * @param string $type Type of object to get metadata table for (e.g., comment, post, term, or user). 1021 * @param string $type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', 1022 * or any other object type with an associated meta table. 1016 1023 * @return string|false Metadata table name, or false if no metadata table exists 1017 1024 */ … … 1033 1040 * @since 3.1.3 1034 1041 * 1035 * @param string $meta_key Meta key. 1036 * @param string|null $meta_type Optional. Type of object metadata is for (e.g., comment, post, term, or user). 1042 * @param string $meta_key Metadata key. 1043 * @param string $meta_type Optional. Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', 1044 * or any other object type with an associated meta table. Default empty. 1037 1045 * @return bool Whether the meta key is considered protected. 1038 1046 */ 1039 function is_protected_meta( $meta_key, $meta_type = null) {1047 function is_protected_meta( $meta_key, $meta_type = '' ) { 1040 1048 $protected = ( '_' == $meta_key[0] ); 1041 1049 … … 1045 1053 * @since 3.2.0 1046 1054 * 1047 * @param bool $protected Whether the key is considered protected. 1048 * @param string $meta_key Meta key. 1049 * @param string|null $meta_type Type of object metadata is for (e.g., comment, post, term, or user). 1055 * @param bool $protected Whether the key is considered protected. 1056 * @param string $meta_key Metadata key. 1057 * @param string $meta_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', 1058 * or any other object type with an associated meta table. 1050 1059 */ 1051 1060 return apply_filters( 'is_protected_meta', $protected, $meta_key, $meta_type ); … … 1053 1062 1054 1063 /** 1055 * Sanitize meta value.1064 * Sanitizes meta value. 1056 1065 * 1057 1066 * @since 3.1.3 1058 1067 * @since 4.9.8 The `$object_subtype` parameter was added. 1059 1068 * 1060 * @param string $meta_key Meta key. 1061 * @param mixed $meta_value Meta value to sanitize. 1062 * @param string $object_type Type of object the meta is registered to. 1069 * @param string $meta_key Metadata key. 1070 * @param mixed $meta_value Metadata value to sanitize. 1071 * @param string $object_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', 1072 * or any other object type with an associated meta table. 1063 1073 * @param string $object_subtype Optional. The subtype of the object type. 1064 *1065 1074 * @return mixed Sanitized $meta_value. 1066 1075 */ … … 1077 1086 * @since 4.9.8 1078 1087 * 1079 * @param mixed $meta_value Meta value to sanitize. 1080 * @param string $meta_key Meta key. 1081 * @param string $object_type Object type. 1088 * @param mixed $meta_value Metadata value to sanitize. 1089 * @param string $meta_key Metadata key. 1090 * @param string $object_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', 1091 * or any other object type with an associated meta table. 1082 1092 * @param string $object_subtype Object subtype. 1083 1093 */ … … 1094 1104 * @since 3.3.0 1095 1105 * 1096 * @param mixed $meta_value Meta value to sanitize. 1097 * @param string $meta_key Meta key. 1098 * @param string $object_type Object type. 1106 * @param mixed $meta_value Metadata value to sanitize. 1107 * @param string $meta_key Metadata key. 1108 * @param string $object_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', 1109 * or any other object type with an associated meta table. 1099 1110 */ 1100 1111 return apply_filters( "sanitize_{$object_type}_meta_{$meta_key}", $meta_value, $meta_key, $object_type ); … … 1118 1129 * @since 5.3.0 Valid meta types expanded to include "array" and "object". 1119 1130 * 1120 * @param string $object_type Type of object this meta is registered to. 1121 * @param string $meta_key Meta key to register. 1131 * @param string $object_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', 1132 * or any other object type with an associated meta table. 1133 * @param string $meta_key Meta key to register. 1122 1134 * @param array $args { 1123 1135 * Data used to describe the meta key when registered. … … 1139 1151 * } 1140 1152 * @param string|array $deprecated Deprecated. Use `$args` instead. 1141 *1142 1153 * @return bool True if the meta key was successfully registered in the global array, false if not. 1143 * Registering a meta key with distinct sanitize and auth callbacks will fire those1144 * callbacks,but will not add to the global registry.1154 * Registering a meta key with distinct sanitize and auth callbacks will fire those callbacks, 1155 * but will not add to the global registry. 1145 1156 */ 1146 1157 function register_meta( $object_type, $meta_key, $args, $deprecated = null ) { … … 1187 1198 * @param array $args Array of meta registration arguments. 1188 1199 * @param array $defaults Array of default arguments. 1189 * @param string $object_type Object type. 1200 * @param string $object_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', 1201 * or any other object type with an associated meta table. 1190 1202 * @param string $meta_key Meta key. 1191 1203 */ … … 1248 1260 * @since 4.9.8 The `$object_subtype` parameter was added. 1249 1261 * 1250 * @param string $object_type The type of object. 1251 * @param string $meta_key The meta key. 1262 * @param string $object_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', 1263 * or any other object type with an associated meta table. 1264 * @param string $meta_key Metadata key. 1252 1265 * @param string $object_subtype Optional. The subtype of the object type. 1253 *1254 1266 * @return bool True if the meta key is registered to the object type and, if provided, 1255 1267 * the object subtype. False if not. … … 1267 1279 * @since 4.9.8 The `$object_subtype` parameter was added. 1268 1280 * 1269 * @param string $object_type The type of object. 1270 * @param string $meta_key The meta key. 1281 * @param string $object_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', 1282 * or any other object type with an associated meta table. 1283 * @param string $meta_key Metadata key. 1271 1284 * @param string $object_subtype Optional. The subtype of the object type. 1272 1285 * @return bool True if successful. False if the meta key was not registered. … … 1316 1329 * @since 4.9.8 The `$object_subtype` parameter was added. 1317 1330 * 1318 * @param string $object_type The type of object. Post, comment, user, term. 1331 * @param string $object_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', 1332 * or any other object type with an associated meta table. 1319 1333 * @param string $object_subtype Optional. The subtype of the object type. 1320 1334 * @return string[] List of registered meta keys. … … 1338 1352 * @since 4.6.0 1339 1353 * 1340 * @param string $object_type Type of object to request metadata for. (e.g. comment, post, term, user) 1354 * @param string $object_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', 1355 * or any other object type with an associated meta table. 1341 1356 * @param int $object_id ID of the object the metadata is for. 1342 1357 * @param string $meta_key Optional. Registered metadata key. If not specified, retrieve all registered … … 1379 1394 1380 1395 /** 1381 * Filter out `register_meta()` args based on a whitelist. 1396 * Filters out `register_meta()` args based on a whitelist. 1397 * 1382 1398 * `register_meta()` args may change over time, so requiring the whitelist 1383 1399 * to be explicitly turned off is a warranty seal of sorts. … … 1388 1404 * @param array $args Arguments from `register_meta()`. 1389 1405 * @param array $default_args Default arguments for `register_meta()`. 1390 *1391 1406 * @return array Filtered arguments. 1392 1407 */ … … 1400 1415 * @since 4.9.8 1401 1416 * 1402 * @param string $object_type Type of object to request metadata for. (e.g. comment, post, term, user) 1417 * @param string $object_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', 1418 * or any other object type with an associated meta table. 1403 1419 * @param int $object_id ID of the object to retrieve its subtype. 1404 1420 * @return string The object subtype or an empty string if unspecified subtype.
Note: See TracChangeset
for help on using the changeset viewer.