钩子文档

{$field_no_prefix}_edit_pre

💡 云策文档标注

概述

此文档介绍 WordPress 中的 {$field_no_prefix}_edit_pre 过滤器,用于在编辑特定文章字段时过滤其值。该过滤器仅适用于以 post_ 为前缀的字段,动态部分 $field_no_prefix 表示字段名去除前缀后的部分。

关键要点

  • 过滤器名称基于字段名,例如 author_edit_pre、title_edit_pre 等。
  • 参数包括 $value(字段值)和 $post_id(文章 ID)。
  • 在 sanitize_post_field() 函数中使用,用于根据上下文清理文章字段。

代码示例

$value = apply_filters( "{$field_no_prefix}_edit_pre", $value, $post_id );

注意事项

  • 仅适用于以 post_ 为前缀的字段,如 post_author、post_title 等。
  • 自 WordPress 2.3.0 版本引入。

📄 原文内容

Filters the value of a specific post field to edit.

Description

Only applied to post fields with a name which is prefixed with post_.

The dynamic portion of the hook name, $field_no_prefix, refers to the post field name minus the post_ prefix. Possible filter names include:

  • author_edit_pre
  • date_edit_pre
  • date_gmt_edit_pre
  • content_edit_pre
  • title_edit_pre
  • excerpt_edit_pre
  • status_edit_pre
  • password_edit_pre
  • name_edit_pre
  • modified_edit_pre
  • modified_gmt_edit_pre
  • content_filtered_edit_pre
  • parent_edit_pre
  • type_edit_pre
  • mime_type_edit_pre

Parameters

$valuemixed
Value of the post field.
$post_idint
Post ID.

Source

$value = apply_filters( "{$field_no_prefix}_edit_pre", $value, $post_id );

Changelog

Version Description
2.3.0 Introduced.