函数文档

media_single_attachment_fields_to_edit()

💡 云策文档标注

概述

media_single_attachment_fields_to_edit() 是一个 WordPress 过滤器函数,用于从附件编辑表单字段中移除非图像附件(如文档、音频等)的特定字段,以简化表单界面。

关键要点

  • 函数作用:过滤附件编辑表单字段,移除非图像附件不需要的字段,如 URL、对齐和图像尺寸选项。
  • 参数:接受两个参数:$form_fields(附件表单字段数组)和 $post(WP_Post 附件对象)。
  • 返回值:返回过滤后的附件表单字段数组。

代码示例

function media_single_attachment_fields_to_edit( $form_fields, $post ) {
    unset( $form_fields['url'], $form_fields['align'], $form_fields['image-size'] );
    return $form_fields;
}

注意事项

  • 此函数自 WordPress 2.5.0 版本引入,主要用于处理非图像附件,确保表单字段与附件类型匹配。
  • 开发者可以自定义此过滤器来调整表单字段,但需注意保持兼容性。

📄 原文内容

Retrieves the single non-image attachment fields to edit form fields.

Parameters

$form_fieldsarrayrequired
An array of attachment form fields.
$postWP_Postrequired
The WP_Post attachment object.

Return

array Filtered attachment form fields.

Source

function media_single_attachment_fields_to_edit( $form_fields, $post ) {
	unset( $form_fields['url'], $form_fields['align'], $form_fields['image-size'] );
	return $form_fields;
}

Changelog

Version Description
2.5.0 Introduced.