Show Custom Comment Fields when editing in admin

I'm using the Custom Comment plugin to add custom fields to my comments.This plugin lets you define more fields f

I'm using the Custom Comment plugin to add custom fields to my comments.

This plugin lets you define more fields for comment to let your visitors include their facebook, twitter and ... in their comments

Everything is working as expected. However, the custom fields don't show up when I edit a comment in the admin side. Currently it only shows the default fields - name, email, url, comment.

Is there an action or a filter that can be used to show this comments custom fields?

I'm using the Custom Comment plugin to add custom fields to my comments.

This plugin lets you define more fields for comment to let your visitors include their facebook, twitter and ... in their comments

Everything is working as expected. However, the custom fields don't show up when I edit a comment in the admin side. Currently it only shows the default fields - name, email, url, comment.

Is there an action or a filter that can be used to show this comments custom fields?

Share Improve this question edited Jan 19, 2013 at 23:14 brasofilo 22.1k8 gold badges70 silver badges266 bronze badges asked Jan 19, 2013 at 20:15 ChrisChris 4532 gold badges15 silver badges31 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 4

Inserting a meta box in the Comment edit screen is the same as in the post types screens. But it can only be placed on the wide column, the sidebar seems not to accept other boxes.

To capture the data that's being posted, I only found the filter comment_edit_redirect.

This has to be adapted to work with the plugin. The custom field in this example is meta_comment_field. See code comments:

// SAVE COMMENT META
// only found this hook to process the POST
add_filter( 'comment_edit_redirect',  'save_comment_wpse_82317', 10, 2 );

// META BOX
add_action( 'add_meta_boxes', 'add_custom_box_wpse_82317' );

/**
 * Save Custom Comment Field
 * This hook deals with the redirect after saving, we are only taking advantage of it
 */
function save_comment_wpse_82317( $location, $comment_id )
{
    // Not allowed, return regular value without updating meta
    if ( !wp_verify_nonce( $_POST['noncename_wpse_82317'], plugin_basename( __FILE__ ) ) 
        && !isset( $_POST['meta_comment_field'] ) 
        ) 
        return $location;

    // Update meta
    update_comment_meta( 
        $comment_id, 
        'meta_comment_field', 
        sanitize_text_field( $_POST['meta_comment_field'] ) 
    );

    // Return regular value after updating  
    return $location;
}

/**
 * Add Comment meta box 
 */
function add_custom_box_wpse_82317() 
{
    add_meta_box( 
        'section_id_wpse_82317',
        __( 'Meta Comment Meta' ),
        'inner_custom_box_wpse_82317',
        'comment',
        'normal'
    );
}

/**
 * Render meta box with Custom Field 
 */
function inner_custom_box_wpse_82317( $comment ) 
{
    // Use nonce for verification
    wp_nonce_field( plugin_basename( __FILE__ ), 'noncename_wpse_82317' );

    $c_meta = get_comment_meta( $comment->comment_ID, 'meta_comment_field', true );
    echo "<input type='text' id='meta_comment_field' name='meta_comment_field' value='", 
        esc_attr( $c_meta ), 
        "' size='25' />";
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745634599a4637312.html

相关推荐

  • Show Custom Comment Fields when editing in admin

    I'm using the Custom Comment plugin to add custom fields to my comments.This plugin lets you define more fields f

    8小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信