钩子文档

add_attachment

💡 云策文档标注

概述

add_attachment 是一个 WordPress Hook,在附件被添加时触发,通常用于在附件创建后执行自定义操作。

关键要点

  • 触发时机:当通过 wp_insert_attachment() 函数添加附件时调用。
  • 参数:$post_id(整数类型),表示附件的 ID。
  • 源位置:在 wp-includes/post.php 文件中定义。
  • 相关函数:与 wp_insert_post() 关联,用于插入或更新帖子。
  • 版本历史:自 WordPress 2.0.0 版本引入。

📄 原文内容

Fires once an attachment has been added.

Parameters

$post_idint
Attachment ID.

More Information

This hook is called when an attachment created by wp_insert_attachment()  in wp-includes/post.php.

Source

do_action( 'add_attachment', $post_id );

Changelog

Version Description
2.0.0 Introduced.