从注册密钥列表中取消注册元密钥。

原型

unregister_meta_key( string $object_type, string $meta_key, string $object_subtype = '' )

参数

$object_type (string) (Required) 对象的类型。

$meta_key (string) (Required) 元键。

$object_subtype (string) (Optional)  对象类型的子类型。

返回值

(bool)  如果成功则为真。如果未注册元键,则返回false。

源文件

路径:wp-includes/meta.php

<?php
...
function unregister_meta_key( $object_type, $meta_key, $object_subtype = '' ) {
	global $wp_meta_keys;
	if ( ! registered_meta_key_exists( $object_type, $meta_key, $object_subtype ) ) {
		return false;
	}
	$args = $wp_meta_keys[ $object_type ][ $object_subtype ][ $meta_key ];
	if ( isset( $args['sanitize_callback'] ) && is_callable( $args['sanitize_callback'] ) ) {
		if ( ! empty( $object_subtype ) ) {
			remove_filter( "sanitize_{$object_type}_meta_{$meta_key}_for_{$object_subtype}", $args['sanitize_callback'] );
		} else {
			remove_filter( "sanitize_{$object_type}_meta_{$meta_key}", $args['sanitize_callback'] );
		}
	}
	if ( isset( $args['auth_callback'] ) && is_callable( $args['auth_callback'] ) ) {
		if ( ! empty( $object_subtype ) ) {
			remove_filter( "auth_{$object_type}_meta_{$meta_key}_for_{$object_subtype}", $args['auth_callback'] );
		} else {
			remove_filter( "auth_{$object_type}_meta_{$meta_key}", $args['auth_callback'] );
		}
	}
	unset( $wp_meta_keys[ $object_type ][ $object_subtype ][ $meta_key ] );
	// Do some clean up
	if ( empty( $wp_meta_keys[ $object_type ][ $object_subtype ] ) ) {
		unset( $wp_meta_keys[ $object_type ][ $object_subtype ] );
	}
	if ( empty( $wp_meta_keys[ $object_type ] ) ) {
		unset( $wp_meta_keys[ $object_type ] );
	}
	return true;
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/unregister_meta_key/