function mbdb_book_grid_meta_boxes()
{
    $mbdb_book_grid_metabox = new_cmb2_box(array('id' => 'mbdb_book_grid_metabox', 'title' => __('Book Grid Settings', 'mooberry-book-manager'), 'object_types' => array('page'), 'context' => 'normal', 'priority' => 'default', 'show_names' => true));
    $mbdb_book_grid_metabox->add_field(array('name' => __('Display Books on This Page?', 'mooberry-book-manager'), 'id' => '_mbdb_book_grid_display', 'type' => 'select', 'default' => 'no', 'options' => array('yes' => __('Yes', 'mooberry-book-manager'), 'no' => __('No', 'mooberry-book-manager'))));
    $mbdb_book_grid_metabox->add_field(array('name' => __('Books to Display', 'mooberry-book-manager'), 'id' => '_mbdb_book_grid_books', 'type' => 'select', 'options' => mbdb_book_grid_selection_options()));
    $mbdb_book_grid_metabox->add_field(array('name' => __('Select Books', 'mooberry-book-manager'), 'id' => '_mbdb_book_grid_custom', 'type' => 'multicheck', 'options' => mbdb_get_book_array()));
    $mbdb_book_grid_metabox->add_field(array('name' => __('Select Genres', 'mooberry-book-manager'), 'id' => '_mbdb_book_grid_genre', 'type' => 'multicheck', 'options' => mbdb_get_term_options('mbdb_genre')));
    $mbdb_book_grid_metabox->add_field(array('name' => __('Select Series', 'mooberry-book-manager'), 'id' => '_mbdb_book_grid_series', 'type' => 'multicheck', 'options' => mbdb_get_term_options('mbdb_series')));
    $mbdb_book_grid_metabox->add_field(array('name' => __('Select Tags', 'mooberry-book-manager'), 'id' => '_mbdb_book_grid_tag', 'type' => 'multicheck', 'options' => mbdb_get_term_options('mbdb_tag')));
    $mbdb_book_grid_metabox->add_field(array('name' => __('Select Publishers', 'mooberry-book-manager'), 'id' => '_mbdb_book_grid_publisher', 'type' => 'multicheck', 'options' => mbdb_get_publishers('no')));
    $mbdb_book_grid_metabox->add_field(array('name' => __('Select Editors', 'mooberry-book-manager'), 'id' => '_mbdb_book_grid_editor', 'type' => 'multicheck', 'options' => mbdb_get_term_options('mbdb_editor')));
    $mbdb_book_grid_metabox->add_field(array('name' => __('Select Illustrators', 'mooberry-book-manager'), 'id' => '_mbdb_book_grid_illustrator', 'type' => 'multicheck', 'options' => mbdb_get_term_options('mbdb_illustrator')));
    $mbdb_book_grid_metabox->add_field(array('name' => __('Select Cover Artists', 'mooberry-book-manager'), 'id' => '_mbdb_book_grid_cover_artist', 'type' => 'multicheck', 'options' => mbdb_get_term_options('mbdb_cover_artist')));
    $group_by_options = mbdb_book_grid_group_by_options();
    $count = count($group_by_options);
    for ($x = 1; $x < $count; $x++) {
        $mbdb_book_grid_metabox->add_field(array('name' => __('Group Books By', 'mooberry-book-manager'), 'id' => '_mbdb_book_grid_group_by_level_' . $x, 'type' => 'select', 'options' => $group_by_options));
        // put a warning at the 5th level
        if ($x == 5) {
            $mbdb_book_grid_metabox->add_field(array('name' => __('Warning: Setting more than 5 levels could cause the page to timeout and not display.', 'mooberry-book-manager'), 'type' => 'title', 'id' => '_mbdb_book_grid_warning', 'attributes' => array('display' => 'none')));
        }
    }
    $mbdb_book_grid_metabox->add_field(array('name' => __('Order By', 'mooberry-book-manager'), 'id' => '_mbdb_book_grid_order', 'type' => 'select', 'options' => mbdb_book_grid_order_options()));
    $mbdb_book_grid_metabox->add_field(array('name' => __('Use default cover height?', 'mooberry-book-manager'), 'id' => '_mbdb_book_grid_cover_height_default', 'type' => 'select', 'default' => 'yes', 'options' => array('yes' => __('Yes', 'mooberry-book-manager'), 'no' => __('No', 'mooberry-book-manager'))));
    $mbdb_book_grid_metabox->add_field(array('name' => __('Book Cover Height (px)', 'mooberry-book-manager'), 'id' => '_mbdb_book_grid_cover_height', 'type' => 'text_small', 'attributes' => array('type' => 'number', 'pattern' => '\\d*', 'min' => 50)));
    $mbdb_book_grid_metabox->add_field(array('name' => __('Additional Content (bottom)', 'mooberry-book-manager'), 'id' => '_mbdb_book_grid_description_bottom', 'type' => 'wysiwyg', 'description' => __('This displays under the book grid.', 'mooberry-book-manager'), 'options' => array('wpautop' => true, 'media_buttons' => true, 'textarea_rows' => 10, 'tabindex' => '', 'editor_css' => '', 'editor_class' => '', 'teeny' => false, 'dfw' => false, 'tinymce' => true, 'quicktags' => true)));
    $mbdb_book_grid_metabox = apply_filters('mbdb_book_grid_meta_boxes', $mbdb_book_grid_metabox);
}
function mbdb_get_book_dropdown($selected_bookID)
{
    $books = mbdb_get_book_array();
    foreach ($books as $book_id => $book_title) {
        $selected = $selected_bookID == $book_id ? ' selected' : '';
        echo apply_filters('mbdb_get_book_dropdown_option', '<option value="' . esc_attr($book_id) . '"' . $selected . '>' . esc_html($book_title) . '</option>');
    }
}