钩子文档

wp_save_post_revision_post_has_changed

💡 云策文档标注

概述

wp_save_post_revision_post_has_changed 是一个 WordPress 过滤器,用于在保存文章修订时判断文章是否已更改。它允许开发者基于自定义逻辑来覆盖默认的修订保存行为。

关键要点

  • 此过滤器用于在 wp_save_post_revision() 函数中检查文章是否有变化,从而决定是否创建新修订。
  • 默认情况下,仅当修订字段(如标题、内容)有变化时才保存修订;此过滤器可添加额外检查。
  • 参数包括 $post_has_changed(布尔值,表示文章是否已更改)、$latest_revision(最新修订的 WP_Post 对象)和 $post(当前文章的 WP_Post 对象)。
  • 过滤器在 WordPress 4.1.0 版本中引入。

📄 原文内容

Filters whether a post has changed.

Description

By default a revision is saved only if one of the revisioned fields has changed.
This filter allows for additional checks to determine if there were changes.

Parameters

$post_has_changedbool
Whether the post has changed.
$latest_revisionWP_Post
The latest revision post object.
$postWP_Post
The post object.

Source

$post_has_changed = (bool) apply_filters( 'wp_save_post_revision_post_has_changed', $post_has_changed, $latest_revision, $post );

Changelog

Version Description
4.1.0 Introduced.