The WordPress Studio Framework can also be used to extend the Comment metabox with custom fields.
Comment Metabox Framework Arguments
Name | Type | Default | Description |
---|---|---|---|
title | string | Title of the comment metabox | |
data_type | string | serialize | Database save option type (serialize | unserialize) |
priority | string | default | The priority within the context where the boxes should show. (high | low | default) |
show_restore | bool | false | Flag to display restore button of the comment metabox |
theme | string | dark | The theme framework (dark | light) |
class | string | Extra CSS classes (space separated) to append to the main framework | |
defaults | array | Sets all default values from an external array (optional) |
Comment Metabox Framework Example
// Check to see if the WPSF class exists
if ( class_exists( 'WPSF' ) ){
// Set unique slug ID
$prefix = 'custom_comment_options';
// Create comment metabox
WPSF::createCommentMetabox( $prefix, array(
'title' => 'Custom Comment Options',
));
// Create section
WPSF::createSection( $prefix, array(
'fields' => array(
array(
'id' => 'example-text',
'type' => 'text',
'title' => 'Example Text',
),
array(
'id' => 'example-textarea',
'type' => 'textarea',
'title' => 'Example Textarea',
),
array(
'id' => 'example-select',
'type' => 'select',
'title' => 'Example Select',
'options' => array(
'option1' => 'Option One',
'option2' => 'Option Two',
'option3' => 'Option Three',
)
),
)
));
}
Extract Option Value (data_type => serialize)
$meta = get_comment_meta( get_comment_ID(), 'custom_comment_options', true );
echo $meta['example-text'];
echo $meta['example-textarea'];
Extract Option Value (data_type => unserialize)
echo get_comment_meta( get_comment_ID(), 'example-text', true );
echo get_comment_meta( get_comment_ID(), 'example-textarea', true );