要在各个编辑页面上显示内容,需要将自定义元框添加到评论编辑页面。你要用钥匙comment 对于$page 的参数add_meta_box.
<?php
add_action( \'add_meta_boxes_comment\', \'pmg_comment_tut_add_meta_box\' );
function pmg_comment_tut_add_meta_box()
{
    add_meta_box( \'pmg-comment-title\', __( \'Comment Title\' ), \'pmg_comment_tut_meta_box_cb\', \'comment\', \'normal\', \'high\' );
}
function pmg_comment_tut_meta_box_cb( $comment )
{
    $title = get_comment_meta( $comment->comment_ID, \'pmg_comment_title\', true );
    wp_nonce_field( \'pmg_comment_update\', \'pmg_comment_update\', false );
    ?>
    <p>
        <label for="pmg_comment_title"><?php _e( \'Comment Title\' ); ?></label>;
        <input type="text" name="pmg_comment_title" value="<?php echo esc_attr( $title ); ?>" class="widefat" />
    </p>
    <?php
}
 您可能还希望能够保存来自管理员的更改。你可以加入
edit_comment 这样做。
<?php
add_action( \'edit_comment\', \'pmg_comment_tut_edit_comment\' );
function pmg_comment_tut_edit_comment( $comment_id )
{
    if( ! isset( $_POST[\'pmg_comment_update\'] ) || ! wp_verify_nonce( $_POST[\'pmg_comment_update\'], \'pmg_comment_update\' ) )
        return;
    if( isset( $_POST[\'pmg_comment_title\'] ) )
        update_comment_meta( $comment_id, \'pmg_comment_title\', esc_attr( $_POST[\'pmg_comment_title\'] ) );
}
 我写了一个
tutorial 如果您对了解更多内容感兴趣,请参阅上面的代码片段。
在注释列表表中显示数据的步骤类似于adding custom columns to post list tables.
为了确保我们得到了正确的屏幕load-edit-comments.php, 抓取当前屏幕,然后连接到manage_{$screen->id}_columns 向注释列表表中添加另一列。
<?php
add_action(\'load-edit-comments.php\', \'wpse64973_load\');
function wpse64973_load()
{
    $screen = get_current_screen();
    add_filter("manage_{$screen->id}_columns", \'wpse64973_add_columns\');
}
 您连接到的函数
manage_{$screen->id}_columns 只需要修改关联数组以包含列。这是一个
$key => $label 配对--确保记住密钥,我们稍后将使用它。继续使用上面的评论标题。
最后,我们需要manage_comments_custom_column 在实际列表中回显注释标题。这很直截了当。我在这里使用了switch语句,因为它很容易扩展到包含更多自定义列。
任意列$key 前面添加的参数将是传递到挂钩函数的第一个参数。
<?php
add_action(\'manage_comments_custom_column\', \'wpse64973_column_cb\', 10, 2);
function wpse64973_column_cb($col, $comment_id)
{
    // you could expand the switch to take care of other custom columns
    switch($col)
    {
        case \'title\':
            if($t = get_comment_meta($comment_id, \'pmg_comment_title\', true))
            {
                echo esc_html($t);
            }
            else
            {
                esc_html_e(\'No Title\', \'wpse64973\');
            }
            break;
    }
}
 注释tut和上述自定义列表列的代码是
here as a plugin.