函数文档

wp_create_initial_comment_meta()

💡 云策文档标注

概述

wp_create_initial_comment_meta() 函数用于注册评论的初始元数据,具体为笔记状态元键 '_wp_note_status'。该函数通过 register_meta() 定义元数据的类型、描述、REST API 支持及权限控制。

关键要点

  • 函数 wp_create_initial_comment_meta() 在 WordPress 6.9.0 版本中引入。
  • 注册的元键为 '_wp_note_status',类型为字符串,用于表示笔记的解决状态。
  • 元数据在 REST API 中可见,允许的值为 'resolved' 或 'reopen'。
  • 通过 auth_callback 确保只有具有 'edit_comment' 权限的用户才能编辑此元数据。

代码示例

function wp_create_initial_comment_meta() {
	register_meta(
		'comment',
		'_wp_note_status',
		array(
			'type'          => 'string',
			'description'   => __( 'Note resolution status' ),
			'single'        => true,
			'show_in_rest'  => array(
				'schema' => array(
					'type' => 'string',
					'enum' => array( 'resolved', 'reopen' ),
				),
			),
			'auth_callback' => function ( $allowed, $meta_key, $object_id ) {
				return current_user_can( 'edit_comment', $object_id );
			},
		)
	);
}

📄 原文内容

Register initial note status meta.

Source

function wp_create_initial_comment_meta() {
	register_meta(
		'comment',
		'_wp_note_status',
		array(
			'type'          => 'string',
			'description'   => __( 'Note resolution status' ),
			'single'        => true,
			'show_in_rest'  => array(
				'schema' => array(
					'type' => 'string',
					'enum' => array( 'resolved', 'reopen' ),
				),
			),
			'auth_callback' => function ( $allowed, $meta_key, $object_id ) {
				return current_user_can( 'edit_comment', $object_id );
			},
		)
	);
}

Changelog

Version Description
6.9.0 Introduced.