post_comment_meta_box() WordPress Function
The post_comment_meta_box() function displays a meta box on the comment editing screen for a given post type. This function is useful for adding custom fields to the comment editing screen for a specific post type. For example, you could use this function to add a text field for the author's name or a select field for the author's country. The post_comment_meta_box() function takes two arguments: the post type and an array of fields. The array of fields is an associative array, where the keys are the field names and the values are the field labels. Here is an example of how to use the post_comment_meta_box() function: add_action( 'add_meta_boxes', 'my_comment_meta_box' ); function my_comment_meta_box() { add_meta_box( 'comment_meta_box', // ID 'My Comment Meta Box', // Title 'post_comment_meta_box', // Callback 'post', // Post type 'normal', // Context 'high' // Priority ); } function post_comment_meta_box( $post, $args ) { $fields = array( 'name' => 'Name', 'country' => 'Country' ); foreach ( $fields as $field => $label ) { echo '
'; echo ' '; echo ''; echo '
'; } }post_comment_meta_box( WP_Post $post ) #
Displays comments for post.
Parameters
- $post
(WP_Post)(Required)Current post object.
Source
File: wp-admin/includes/meta-boxes.php
function post_comment_meta_box( $post ) { wp_nonce_field( 'get-comments', 'add_comment_nonce', false ); ?> <p class="hide-if-no-js" id="add-new-comment"><button type="button" class="button" onclick="window.commentReply && commentReply.addcomment(<?php echo $post->ID; ?>);"><?php _e( 'Add Comment' ); ?></button></p> <?php $total = get_comments( array( 'post_id' => $post->ID, 'number' => 1, 'count' => true, ) ); $wp_list_table = _get_list_table( 'WP_Post_Comments_List_Table' ); $wp_list_table->display( true ); if ( 1 > $total ) { echo '<p id="no-comments">' . __( 'No comments yet.' ) . '</p>'; } else { $hidden = get_hidden_meta_boxes( get_current_screen() ); if ( ! in_array( 'commentsdiv', $hidden, true ) ) { ?> <script type="text/javascript">jQuery(function(){commentsBox.get(<?php echo $total; ?>, 10);});</script> <?php } ?> <p class="hide-if-no-js" id="show-comments"><a href="#commentstatusdiv" onclick="commentsBox.load(<?php echo $total; ?>);return false;"><?php _e( 'Show comments' ); ?></a> <span class="spinner"></span></p> <?php } wp_comment_trashnotice(); }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
2.8.0 | Introduced. |