unregister_meta_key

The timeline below displays how wordpress function unregister_meta_key has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.2

/**
 * Unregisters a meta key from the list of registered keys.
 *
 * @since 4.6.0
 * @since 4.9.8 The `$object_subtype` parameter was added.
 *
 * @param string $object_type    Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
 *                               or any other object type with an associated meta table.
 * @param string $meta_key       Metadata key.
 * @param string $object_subtype Optional. The subtype of the object type. Default empty string.
 * @return bool True if successful. False if the meta key was not registered.
 */
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;
}

WordPress Version: 5.4

/**
 * Unregisters a meta key from the list of registered keys.
 *
 * @since 4.6.0
 * @since 4.9.8 The `$object_subtype` parameter was added.
 *
 * @param string $object_type    Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
 *                               or any other object type with an associated meta table.
 * @param string $meta_key       Metadata key.
 * @param string $object_subtype Optional. The subtype of the object type.
 * @return bool True if successful. False if the meta key was not registered.
 */
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;
}

WordPress Version: 9.8

/**
 * Unregisters a meta key from the list of registered keys.
 *
 * @since 4.6.0
 * @since 4.9.8 The `$object_subtype` parameter was added.
 *
 * @param string $object_type    The type of object.
 * @param string $meta_key       The meta key.
 * @param string $object_subtype Optional. The subtype of the object type.
 * @return bool True if successful. False if the meta key was not registered.
 */
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;
}

WordPress Version: 9.3

/**
 * Unregisters a meta key from the list of registered keys.
 *
 * @since 4.6.0
 *
 * @param string $object_type The type of object.
 * @param string $meta_key    The meta key.
 * @return bool True if successful. False if the meta key was not registered.
 */
function unregister_meta_key($object_type, $meta_key)
{
    global $wp_meta_keys;
    if (!registered_meta_key_exists($object_type, $meta_key)) {
        return false;
    }
    $args = $wp_meta_keys[$object_type][$meta_key];
    if (isset($args['sanitize_callback']) && is_callable($args['sanitize_callback'])) {
        remove_filter("sanitize_{$object_type}_meta_{$meta_key}", $args['sanitize_callback']);
    }
    if (isset($args['auth_callback']) && is_callable($args['auth_callback'])) {
        remove_filter("auth_{$object_type}_meta_{$meta_key}", $args['auth_callback']);
    }
    unset($wp_meta_keys[$object_type][$meta_key]);
    // Do some clean up
    if (empty($wp_meta_keys[$object_type])) {
        unset($wp_meta_keys[$object_type]);
    }
    return true;
}

WordPress Version: .20

/**
 * Unregisters a meta key from the list of registered keys.
 *
 * @since 4.6.0
 * @since 4.9.8 The `$object_subtype` parameter was added.
 *
 * @param string $object_type    The type of object.
 * @param string $meta_key       The meta key.
 * @param string $object_subtype Optional. The subtype of the object type.
 * @return bool True if successful. False if the meta key was not registered.
 */
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;
}

WordPress Version: 9.2

/**
 * Unregisters a meta key from the list of registered keys.
 *
 * @since 4.6.0
 *
 * @param string $object_type The type of object.
 * @param string $meta_key    The meta key.
 * @return bool True if successful. False if the meta key was not registered.
 */
function unregister_meta_key($object_type, $meta_key)
{
    global $wp_meta_keys;
    if (!registered_meta_key_exists($object_type, $meta_key)) {
        return false;
    }
    $args = $wp_meta_keys[$object_type][$meta_key];
    if (isset($args['sanitize_callback']) && is_callable($args['sanitize_callback'])) {
        remove_filter("sanitize_{$object_type}_meta_{$meta_key}", $args['sanitize_callback']);
    }
    if (isset($args['auth_callback']) && is_callable($args['auth_callback'])) {
        remove_filter("auth_{$object_type}_meta_{$meta_key}", $args['auth_callback']);
    }
    unset($wp_meta_keys[$object_type][$meta_key]);
    // Do some clean up
    if (empty($wp_meta_keys[$object_type])) {
        unset($wp_meta_keys[$object_type]);
    }
    return true;
}

WordPress Version: .10

/**
 * Unregisters a meta key from the list of registered keys.
 *
 * @since 4.6.0
 * @since 4.9.8 The `$object_subtype` parameter was added.
 *
 * @param string $object_type    The type of object.
 * @param string $meta_key       The meta key.
 * @param string $object_subtype Optional. The subtype of the object type.
 * @return bool True if successful. False if the meta key was not registered.
 */
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;
}

WordPress Version: 4.6

/**
 * Unregisters a meta key from the list of registered keys.
 *
 * @since 4.6.0
 *
 * @param string $object_type The type of object.
 * @param string $meta_key    The meta key.
 * @return bool True if successful. False if the meta key was not registered.
 */
function unregister_meta_key($object_type, $meta_key)
{
    global $wp_meta_keys;
    if (!registered_meta_key_exists($object_type, $meta_key)) {
        return false;
    }
    $args = $wp_meta_keys[$object_type][$meta_key];
    if (isset($args['sanitize_callback']) && is_callable($args['sanitize_callback'])) {
        remove_filter("sanitize_{$object_type}_meta_{$meta_key}", $args['sanitize_callback']);
    }
    if (isset($args['auth_callback']) && is_callable($args['auth_callback'])) {
        remove_filter("auth_{$object_type}_meta_{$meta_key}", $args['auth_callback']);
    }
    unset($wp_meta_keys[$object_type][$meta_key]);
    // Do some clean up
    if (empty($wp_meta_keys[$object_type])) {
        unset($wp_meta_keys[$object_type]);
    }
    return true;
}