Uses
Uses | Description |
---|---|
wp-includes/meta.php: get_object_subtype() | Returns the object subtype for a given object ID of a specific type. |
wp-includes/load.php: wp_installing() | Check or set whether WordPress is in “installation” mode. |
Filters into default_{$object_type}_metadata and adds in default value.
(mixed) (Required) Current value passed to filter.
(int) (Required) ID of the object metadata is for.
(string) (Required) Metadata key.
(bool) (Required) If true, return only the first value of the specified meta_key. This parameter has no effect if meta_key is not specified.
(string) (Required) Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', or any other object type with an associated meta table.
(mixed) Single metadata default, or array of defaults.
File: wp-includes/meta.php
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; }
Version | Description |
---|---|
5.5.0 | Introduced. |
© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/filter_default_metadata