IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
|
|
|
536 | 536 | } |
537 | 537 | } |
538 | 538 | |
| 539 | return get_metadata_default( $meta_type, $meta_key, $single, $object_id ); |
| 540 | } |
| 541 | |
| 542 | /** |
| 543 | * Retrieve metadata data default for the specified object. |
| 544 | * |
| 545 | * @since 5.2.0 |
| 546 | * |
| 547 | * @param string $meta_type Type of object metadata is for (e.g., comment, post, term, or user). |
| 548 | * @param string $meta_key Optional. Metadata key. If not specified, retrieve all metadata for |
| 549 | * the specified object. |
| 550 | * @param bool $single Optional, default is false. |
| 551 | * If true, return only the first value of the specified meta_key. |
| 552 | * This parameter has no effect if meta_key is not specified. |
| 553 | * @param int $object_id Optional, default is 0. |
| 554 | * ID of the object metadata is for |
| 555 | * @return mixed Single metadata value, or array of values |
| 556 | */ |
| 557 | function get_metadata_default( $meta_type, $meta_key, $single = false, $object_id = 0 ) { |
539 | 558 | if ( $single ) { |
540 | | return ''; |
| 559 | $value = ''; |
541 | 560 | } else { |
542 | | return array(); |
| 561 | $value = array(); |
543 | 562 | } |
| 563 | |
| 564 | /** |
| 565 | * |
| 566 | * @since 5.2.0 |
| 567 | * |
| 568 | * @param array|string $value The value should return - a single metadata value, |
| 569 | * or an array of values. |
| 570 | * @param string $meta_type Type of object metadata is for (e.g., comment, post, term, or user). |
| 571 | * @param string $meta_key Meta key. |
| 572 | * @param bool $single Whether to return only the first value of the specified $meta_key. |
| 573 | * @param int $object_id Object ID. |
| 574 | */ |
| 575 | $value = apply_filters( "default_{$meta_type}_metadata", $value, $meta_type, $meta_key, $single, $object_id ); |
| 576 | |
| 577 | return $value; |
544 | 578 | } |
545 | 579 | |
546 | 580 | /** |
… |
… |
|
1141 | 1175 | 'type' => 'string', |
1142 | 1176 | 'description' => '', |
1143 | 1177 | 'single' => false, |
| 1178 | 'default' => null, |
1144 | 1179 | 'sanitize_callback' => null, |
1145 | 1180 | 'auth_callback' => null, |
1146 | 1181 | 'show_in_rest' => false, |
… |
… |
|
1206 | 1241 | } |
1207 | 1242 | } |
1208 | 1243 | |
| 1244 | if ( false === $args['single'] && ! wp_is_numeric_array( $args['default'] ) ) { |
| 1245 | $args['default'] = null; |
| 1246 | } |
| 1247 | |
| 1248 | if ( null !== $args['default'] ) { |
| 1249 | add_filter( "default_{$object_type}_metadata", "filter_default_metadata", 10, 5 ); |
| 1250 | } |
| 1251 | |
1209 | 1252 | // Global registry only contains meta keys registered with the array of arguments added in 4.6.0. |
1210 | 1253 | if ( ! $has_old_auth_cb && ! $has_old_sanitize_cb ) { |
1211 | 1254 | unset( $args['object_subtype'] ); |
… |
… |
|
1434 | 1477 | */ |
1435 | 1478 | return apply_filters( "get_object_subtype_{$object_type}", $object_subtype, $object_id ); |
1436 | 1479 | } |
| 1480 | |
| 1481 | /** |
| 1482 | * |
| 1483 | * @param $value |
| 1484 | * @param $meta_type |
| 1485 | * @param $meta_key |
| 1486 | * @param $single |
| 1487 | * @param $object_id |
| 1488 | * |
| 1489 | * @return mixed |
| 1490 | */ |
| 1491 | function filter_default_metadata( $value, $meta_type, $meta_key, $single, $object_id ) { |
| 1492 | $metadata = get_registered_meta_keys( $meta_type ); |
| 1493 | if ( ! isset( $metadata[ $meta_key ] ) ) { |
| 1494 | $sub_type = get_object_subtype( $meta_type, $object_id ); |
| 1495 | $metadata = get_registered_meta_keys( $meta_type, $sub_type ); |
| 1496 | if ( ! isset( $metadata[ $meta_key ] ) ) { |
| 1497 | return $value; |
| 1498 | } |
| 1499 | } |
| 1500 | |
| 1501 | if ( $metadata[ $meta_key ]['single'] ) { |
| 1502 | if ( $single ) { |
| 1503 | $value = $metadata[ $meta_key ]['default']; |
| 1504 | } else { |
| 1505 | $value = array( $metadata[ $meta_key ]['default'] ); |
| 1506 | } |
| 1507 | } else { |
| 1508 | if ( $single ) { |
| 1509 | $value = $metadata[ $meta_key ]['default'][0]; |
| 1510 | } else { |
| 1511 | $value = $metadata[ $meta_key ]['default']; |
| 1512 | } |
| 1513 | } |
| 1514 | |
| 1515 | return $value; |
| 1516 | } |
| 1517 | No newline at end of file |