钩子文档

wp_prepare_revision_for_js

💡 云策文档标注

概述

wp_prepare_revision_for_js 是一个 WordPress 过滤器,用于在修订版屏幕上过滤修订版数组数据。它允许开发者自定义传递给 JavaScript 的修订版信息。

关键要点

  • 过滤器名称:wp_prepare_revision_for_js
  • 用途:过滤修订版屏幕上的修订版数组数据
  • 参数:$revisions_data(修订版屏幕的引导数据数组)、$revision(修订版的 WP_Post 对象)、$post(修订版父文章的 WP_Post 对象)
  • 返回值:过滤后的修订版数据数组
  • 引入版本:4.4.0

代码示例

$revisions[ $revision->ID ] = apply_filters( 'wp_prepare_revision_for_js', $revisions_data, $revision, $post );

注意事项

  • 此过滤器在 wp_prepare_revisions_for_js() 函数中被调用,用于准备修订版数据供 JavaScript 使用。
  • 修订版数据数组包含多个字段,如 id、title、author、date、autosave、current、restoreUrl 等,开发者可以基于这些字段进行自定义过滤。

📄 原文内容

Filters the array of revisions used on the revisions screen.

Parameters

$revisions_dataarray
The bootstrapped data for the revisions screen.

  • id int
    Revision ID.
  • title string
    Title for the revision’s parent WP_Post object.
  • author int
    Revision post author ID.
  • date string
    Date the revision was modified.
  • dateShort string
    Short-form version of the date the revision was modified.
  • timeAgo string
    GMT-aware amount of time ago the revision was modified.
  • autosave bool
    Whether the revision is an autosave.
  • current bool
    Whether the revision is both not an autosave and the post modified date matches the revision modified date (GMT-aware).
  • restoreUrl bool|false
    URL if the revision can be restored, false otherwise.

$revisionWP_Post
The revision’s WP_Post object.
$postWP_Post
The revision’s parent WP_Post object.

Source

$revisions[ $revision->ID ] = apply_filters( 'wp_prepare_revision_for_js', $revisions_data, $revision, $post );

Changelog

Version Description
4.4.0 Introduced.