钩子文档

pre_post_update

💡 云策文档标注

概述

pre_post_update 是一个 WordPress Hook,在现有文章更新到数据库之前立即触发。它主要用于在更新操作前修改文章数据。

关键要点

  • 触发时机:在 $wpdb::update() 调用之前,仅针对更新操作(不包括创建)。
  • 参数:$post_id(文章 ID)和 $data(未转义的文章数据数组)。
  • 用途:允许在数据更新到数据库前编辑 $wpdb->posts 的内容。
  • 相关函数:与 wp_insert_post() 关联,用于插入或更新文章。
  • 版本历史:从 WordPress 2.5.0 版本引入。

📄 原文内容

Fires immediately before an existing post is updated in the database.

Parameters

$post_idint
Post ID.
$dataarray
Array of unslashed post data.

More Information

The hook is called just before $wpdb::update(), only on updates (not creates).

This might be useful for editing the contents of $wpdb->posts before the content is updated to the DB.

Source

do_action( 'pre_post_update', $post_id, $data );

Changelog

Version Description
2.5.0 Introduced.