filter_default_metadata
函数
filter_default_metadata ( $value, $object_id, $meta_key, $single, $meta_type )
- 参数
-
-
(mixed)
$value
Current value passed to filter.- Required: 是
-
(int)
$object_id
ID of the object metadata is for.- Required: 是
-
(string)
$meta_key
Metadata key.- Required: 是
-
(bool)
$single
If true, return only the first value of the specified `$meta_key`. This parameter has no effect if `$meta_key` is not specified.- Required: 是
-
(string)
$meta_type
Type of object metadata is for. Accepts ‘post’, ‘comment’, ‘term’, ‘user’, or any other object type with an associated meta table.- Required: 是
-
(mixed)
- 返回值
-
- (mixed) An array of default values if `$single` is false. The default value of the meta field if `$single` is true.
- 定义位置
-
-
wp-includes/meta.php
, line 1530
-
wp-includes/meta.php
- 引入
- 5.5.0
- 弃用
- –
过滤到default_{$object_type}_metadata并加入默认值。
function filter_default_metadata( $value, $object_id, $meta_key, $single, $meta_type ) { global $wp_meta_keys; if ( wp_installing() ) { return $value; } if ( ! is_array( $wp_meta_keys ) || ! isset( $wp_meta_keys[ $meta_type ] ) ) { return $value; } $defaults = array(); foreach ( $wp_meta_keys[ $meta_type ] as $sub_type => $meta_data ) { foreach ( $meta_data as $_meta_key => $args ) { if ( $_meta_key === $meta_key && array_key_exists( 'default', $args ) ) { $defaults[ $sub_type ] = $args; } } } if ( ! $defaults ) { return $value; } // If this meta type does not have subtypes, then the default is keyed as an empty string. if ( isset( $defaults[''] ) ) { $metadata = $defaults['']; } else { $sub_type = get_object_subtype( $meta_type, $object_id ); if ( ! isset( $defaults[ $sub_type ] ) ) { return $value; } $metadata = $defaults[ $sub_type ]; } if ( $single ) { $value = $metadata['default']; } else { $value = array( $metadata['default'] ); } return $value; }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。