钩子文档

update_{$meta_type}_metadata_cache

💡 云策文档标注

概述

本文档介绍 WordPress 中的 update_{$meta_type}_metadata_cache 过滤器钩子,用于短路更新特定类型的元数据缓存。该钩子允许开发者拦截并自定义元数据缓存更新过程。

关键要点

  • 钩子名称是动态的,其中 $meta_type 指代元对象类型,如 blog、post、comment、term、user 或其他关联元表的类型。
  • 返回非空值将有效短路 update_meta_cache() 函数,阻止默认的元数据缓存更新。
  • 常见钩子名称包括 update_blog_metadata_cache、update_post_metadata_cache、update_comment_metadata_cache、update_term_metadata_cache 和 update_user_metadata_cache。
  • 参数包括 $check(是否允许更新给定类型的元缓存)和 $object_ids(要更新元缓存的对象 ID 数组)。
  • 该钩子自 WordPress 5.0.0 版本引入。

代码示例

$check = apply_filters( "update_{$meta_type}_metadata_cache", null, $object_ids );

📄 原文内容

Short-circuits updating the metadata cache of a specific type.

Description

The dynamic portion of the hook name, $meta_type, refers to the meta object type (blog, post, comment, term, user, or any other type with an associated meta table).
Returning a non-null value will effectively short-circuit the function.

Possible hook names include:

  • update_blog_metadata_cache
  • update_post_metadata_cache
  • update_comment_metadata_cache
  • update_term_metadata_cache
  • update_user_metadata_cache

Parameters

$checkmixed
Whether to allow updating the meta cache of the given type.
$object_idsint[]
Array of object IDs to update the meta cache for.

Source

$check = apply_filters( "update_{$meta_type}_metadata_cache", null, $object_ids );

Changelog

Version Description
5.0.0 Introduced.