钩子文档

_wp_post_revision_field_{$field}

💡 云策文档标注

概述

此文档介绍 WordPress 的 _wp_post_revision_field_{$field} 钩子,用于上下文过滤文章修订字段。钩子名称的动态部分 $field 对应修订对象字段名,如 post_title、post_content 或 post_excerpt。

关键要点

  • 钩子名称是动态的,基于 $field 参数,例如 _wp_post_revision_field_post_title。
  • 参数包括 $revision_field(当前修订字段)、$field(当前修订字段名)、$compare_from(WP_Post 修订对象)和 $context(上下文,'to' 或 'from')。
  • 主要用于 wp_get_revision_ui_diff() 函数,在文章修订界面中获取差异比较。
  • 自 WordPress 3.6.0 版本引入。

代码示例

$content_from = $compare_from ? apply_filters( "_wp_post_revision_field_{$field}", $compare_from->$field, $field, $compare_from, 'from' ) : '';

📄 原文内容

Contextually filter a post revision field.

Description

The dynamic portion of the hook name, $field, corresponds to a name of a field of the revision object.

Possible hook names include:

  • _wp_post_revision_field_post_title
  • _wp_post_revision_field_post_content
  • _wp_post_revision_field_post_excerpt

Parameters

$revision_fieldstring
The current revision field to compare to or from.
$fieldstring
The current revision field.
$compare_fromWP_Post
The revision post object to compare to or from.
$contextstring
The context of whether the current revision is the old or the new one. Either 'to' or 'from'.

Source

$content_from = $compare_from ? apply_filters( "_wp_post_revision_field_{$field}", $compare_from->$field, $field, $compare_from, 'from' ) : '';

Changelog

Version Description
3.6.0 Introduced.