函数文档

post_comment_status_meta_box()

💡 云策文档标注

概述

post_comment_status_meta_box() 函数用于在文章编辑屏幕上显示评论状态表单字段,包括评论和 ping 状态选项。它生成一个包含复选框和相关说明的 HTML 表单部分。

关键要点

  • 函数接受一个必需的参数 $post,类型为 WP_Post,表示当前文章对象。
  • 输出评论状态表单,包括“允许评论”和“允许 trackbacks 和 pingbacks”的复选框,使用 checked() 函数设置默认选中状态。
  • 包含一个 Hook:do_action('post_comment_status_meta_box-options', $post),在表单末尾触发,允许开发者添加自定义选项。
  • 相关函数包括 checked()、_e()、__() 和 do_action(),用于处理 HTML 属性、翻译文本和 Hook 调用。
  • 自 WordPress 2.6.0 版本引入,无后续变更记录。

📄 原文内容

Displays comments status form fields.

Parameters

$postWP_Postrequired
Current post object.

Source

function post_comment_status_meta_box( $post ) {
?>
<input name="advanced_view" type="hidden" value="1" />
<p class="meta-options">
<label for="comment_status" class="selectit"><input name="comment_status" type="checkbox" id="comment_status" value="open" <?php checked( $post->comment_status, 'open' ); ?> /> </label><br />
<label for="ping_status" class="selectit"><input name="ping_status" type="checkbox" id="ping_status" value="open" <?php checked( $post->ping_status, 'open' ); ?> />
trackbacks and pingbacks</a>' ),
__( 'https://wordpress.org/documentation/article/introduction-to-blogging/#managing-comments' )
);
?>
</label>

</p>
</pre><p class="wporg-dot-link-list"><a href="https://developer.wordpress.org/reference/files/wp-admin/includes/meta-boxes.php/">View all references</a> <a href="https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/includes/meta-boxes.php#L847">View on Trac</a> <a href="https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/meta-boxes.php#L847-L873">View on GitHub</a></p></section>
<section class="wp-block-wporg-code-reference-hooks"><h2 id="hooks" class="is-toc-heading wp-block-heading has-heading-5-font-size" tabindex="-1" ><a href="#hooks">Hooks</a></h2> <dl><dt class="wp-block-wporg-code-reference-title has-normal-font-size"><a href="https://developer.wordpress.org/reference/hooks/post_comment_status_meta_box-options/"><span class="hook-func">do_action</span>( ‘post_comment_status_meta_box-options’, <nobr><span class="arg-type">WP_Post</span> <span class="arg-name">$post</span></nobr> )</a></dt><dd><p>Fires at the end of the Discussion meta box on the post editing screen.</p>
</dd></dl></section>
<section class="wp-block-wporg-code-reference-related" data-nosnippet="true"><h2 id="related" class="is-toc-heading wp-block-heading has-heading-5-font-size" tabindex="-1" ><a href="#related">Related</a></h2> <section style="margin-top:var(--wp--preset--spacing--20)" class="wp-block-wporg-code-table" id="uses"><figure class="wp-block-table "><table><thead><tr><th scope="col">Uses</th><th scope="col">Description</th></tr></thead><tbody><tr class=""><td><a href="https://developer.wordpress.org/reference/functions/checked/">checked()</a><code>wp-includes/general-template.php

Outputs the HTML checked attribute.

_e()wp-includes/l10n.php

Displays translated text.

__()wp-includes/l10n.php

Retrieves the translation of $text.

do_action()wp-includes/plugin.php

Calls the callback functions that have been added to an action hook.

Show 2 moreShow less

Changelog

Version Description
2.6.0 Introduced.