We create a bunch of meta box instances like this:
$meta_boxes = array(
0 => array(
'id' => 'product',
'title' => 'Product information',
'pages' => array(
0 => 'example_product',
),
'context' => 'normal',
'priority' => 'high',
'fields' => array(
0 => array(
'name' => 'price',
'desc' => 'example: 19,95',
'id' => '_product_price',
'type' => 'currency',
'std' => '0',
),
1 => array(
'name' => 'subtext',
'desc' => 'example: now instead of € 39,95 you only pay',
'id' => '_product_sidenote',
'type' => 'text',
'std' => '0',
),
2 => array(
'name' => '',
'desc' => 'Product information (e.g. a discount). Not orderable directly',
'id' => '_product_information',
'type' => 'checkbox',
'std' => '0',
),
3 => array(
'name' => 'Supply',
'desc' => '',
'id' => '_product_supply',
'type' => 'text',
'std' => '0',
),
4 => array(
'name' => '',
'desc' => 'Unlimited amount?',
'id' => '_product_supply_infinite',
'type' => 'checkbox',
'std' => '0',
),
5 => array(
'name' => 'Max. order amount',
'desc' => '',
'id' => '_product_max_per_order',
'type' => 'text',
'std' => '0',
),
6 => array(
'name' => 'Date',
'desc' => 'E.g. for an event',
'id' => '_product_date',
'type' => 'date',
),
7 => array(
'name' => 'Waitinglist',
'desc' => 'In case there are waiting list spots available',
'id' => '_product_waitinglist',
'type' => 'text',
'std' => '0',
),
),
),
1 => array(
'id' => 'options',
'title' => 'Options',
'pages' => array(
0 => 'example_product',
),
'context' => 'normal',
'priority' => 'high',
'fields' => array(
0 => array(
'name' => '',
'desc' => 'This product can be collected at the store (store can be selected when ordering)',
'id' => '_product_select-dealer',
'type' => 'checkbox',
'std' => '0',
),
1 => array(
'name' => '',
'desc' => 'Product is visible',
'id' => '_product_visible',
'type' => 'checkbox',
'std' => '0',
),
2 => array(
'name' => 'Starting date',
'desc' => 'When the product will be orderable',
'id' => '_product_startdate',
'type' => 'date',
'std' => '',
),
3 => array(
'name' => 'Eind datum',
'desc' => 'When the product will not be orderable anymore',
'id' => '_product_enddate',
'type' => 'date',
'std' => '',
),
4 => array(
'name' => '',
'desc' => 'Product of the month?',
'id' => '_product_product-of-the-month',
'type' => 'checkbox',
'std' => '0',
),
5 => array(
'name' => '',
'desc' => 'Visible on homepage?',
'id' => '_product_homepage',
'type' => 'checkbox',
'std' => '0',
),
),
),
2 => array(
'id' => 'email',
'title' => 'Confirmation e-mail',
'pages' => array(
0 => 'example_product',
),
'context' => 'normal',
'priority' => 'high',
'fields' => array(
0 => array(
'name' => '',
'desc' => '',
'id' => '_product_confirmation-email',
'type' => 'wysiwyg',
'std' => 'Dear member,
Thank you for your order:
[COUNT] x [PRODUCT]
Best regards
example.com',
'teeny' => true,
),
),
),
3 => array(
'id' => 'form',
'title' => 'Form',
'pages' => array(
0 => 'example_product',
),
'context' => 'normal',
'priority' => 'high',
'fields' => array(
0 => array(
'name' => 'Form',
'desc' => 'Select an additional form that has to be filled in',
'id' => '_product_extra-form',
'type' => 'select',
'options' => array(
0 => '',
),
'std' => '',
),
),
),
4 => array(
'id' => 'summary',
'title' => 'Summary',
'pages' => array(
0 => 'example_product',
),
'context' => 'normal',
'priority' => 'high',
'fields' => array(
0 => array(
'name' => '',
'desc' => '',
'id' => '_product_summary',
'type' => 'wysiwyg',
'std' => '',
'teeny' => true,
'rows' => 5,
),
),
),
);
foreach ($meta_boxes as $meta_box) {
if ($meta_box['id'] == 'form') {
add_action("rwmb_after_{$meta_box['id']}", 'add_meta_export_button');
} else {
add_action("rwmb_after_{$meta_box['id']}", 'add_meta_save_button');
}
new RW_Meta_Box($meta_box);
}
Within admin_init … of course a lot of other things are going on in there too so I only posted the sections that seem relevant for the meta box plugin. In case you are wondering why there are numerical indexes within the array, I just did a var_export($meta_boxes) to get the result of the things going on/building the meta boxes array in the init function.
Please let me know if there is anything else I need to provide!