钩子文档

wp_save_post_revision_check_for_changes

💡 云策文档标注

概述

wp_save_post_revision_check_for_changes 是一个 WordPress 过滤器,用于控制是否在保存新修订版本前检查文章是否已更改。默认情况下,仅当修订字段有变化时才保存修订,此过滤器可覆盖此行为。

关键要点

  • 过滤器名称:wp_save_post_revision_check_for_changes
  • 作用:过滤是否检查文章自最新修订以来的变化,以决定是否保存新修订
  • 参数:$check_for_changes(布尔值,默认 true)、$latest_revision(WP_Post 对象)、$post(WP_Post 对象)
  • 默认行为:检查变化,有变化才保存修订
  • 可覆盖:允许强制保存修订,即使无变化
  • 相关函数:wp_save_post_revision()
  • 引入版本:3.6.0

代码示例

if ( isset( $latest_revision ) && apply_filters( 'wp_save_post_revision_check_for_changes', true, $latest_revision, $post ) ) {

📄 原文内容

Filters whether the post has changed since the latest revision.

Description

By default a revision is saved only if one of the revisioned fields has changed.
This filter can override that so a revision is saved even if nothing has changed.

Parameters

$check_for_changesbool
Whether to check for changes before saving a new revision.
Default true.
$latest_revisionWP_Post
The latest revision post object.
$postWP_Post
The post object.

Source

if ( isset( $latest_revision ) && apply_filters( 'wp_save_post_revision_check_for_changes', true, $latest_revision, $post ) ) {

Changelog

Version Description
3.6.0 Introduced.