有一个工作工具集可以很好地用于这种附加组件,称为CMB2。您可以将所需的所有字段和按钮添加为metabox系列的一部分。元盒是wordpress管理部分的组成部分。
https://wordpress.org/plugins/cmb2/
例如片段:
function custom_post_status() {
register_post_status( \'spam\', array(
\'label\' => _x( \'Spam\', \'post\' ),
\'public\' => false,
\'exclude_from_search\' => true,
\'show_in_admin_all_list\' => true,
\'show_in_admin_status_list\' => true,
\'label_count\' => _n_noop( \'SPAM <span class="count">(%s)</span>\',
\'SPAM <span class="count">(%s)</span>\' ),
) );
}
add_action( \'cmb2_admin_init\', \'cmb2_sample_metaboxes\' );
/**
* Define the metabox and field configurations.
*/
function cmb2_sample_metaboxes() {
// Start with an underscore to hide fields from custom fields list
$prefix = \'_yourprefix_\';
/**
* Initiate the metabox
*/
$cmb = new_cmb2_box( array(
\'id\' => \'test_metabox\',
\'title\' => __( \'Test Metabox\', \'cmb2\' ),
\'object_types\' => \'spam\', \' // <<<==== YOUR POST STATUS NAME
\'context\' => \'normal\',
\'priority\' => \'high\',
\'show_names\' => true, // Show field names on the left
// \'cmb_styles\' => false, // false to disable the CMB stylesheet
// \'closed\' => true, // Keep the metabox closed by default
) );
// Regular text field
$cmb->add_field( array(
\'name\' => __( \'Test Text\', \'cmb2\' ),
\'desc\' => __( \'field description (optional)\', \'cmb2\' ),
\'id\' => $prefix . \'text\',
\'type\' => \'text\',
\'show_on_cb\' => \'cmb2_hide_if_no_cats\', // function should return a bool value
// \'sanitization_cb\' => \'my_custom_sanitization\', // custom sanitization callback parameter
// \'escape_cb\' => \'my_custom_escaping\', // custom escaping callback parameter
// \'on_front\' => false, // Optionally designate a field to wp-admin only
// \'repeatable\' => true,
) );
// URL text field
$cmb->add_field( array(
\'name\' => __( \'Website URL\', \'cmb2\' ),
\'desc\' => __( \'field description (optional)\', \'cmb2\' ),
\'id\' => $prefix . \'url\',
\'type\' => \'text_url\',
// \'protocols\' => array(\'http\', \'https\', \'ftp\', \'ftps\', \'mailto\', \'news\', \'irc\', \'gopher\', \'nntp\', \'feed\', \'telnet\'), // Array of allowed protocols
// \'repeatable\' => true,
) );
// Email text field
$cmb->add_field( array(
\'name\' => __( \'Test Text Email\', \'cmb2\' ),
\'desc\' => __( \'field description (optional)\', \'cmb2\' ),
\'id\' => $prefix . \'email\',
\'type\' => \'text_email\',
// \'repeatable\' => true,
) );
// Add other metaboxes as needed
}
这里可以看到更多
https://github.com/CMB2/CMB2/wiki/Basic-Usage#create-a-metabox