To add to what Justin mentioned, just at standard function/add_action inside a basic plugin file is enough. The only difference between pasting it in the example below and pasting it into functions.php is going to be the plugin comment block at the top, and the need to activate the plugin to have it work.
Edit: Don’t copy/paste this exactly, you’ll get undefined wds_page_builder_get_parts() function errors.
<?php
/*
Plugin Name: Plugin Name
Plugin URI: Plugin URI
Description: Description of the plugin
Version: 1.0
Author: WebDevStudios
Author URI: https://www.webdevstudios.com
License: GPLv2
Text Domain: Text domain to use
*/
function davidshq( $meta_boxes ) {
$prefix = '_prefix_';
$cmb = new_cmb2_box( array(
'id' => 'wds_simple_page_builder',
'title' => esc_html__( 'Page Builder', 'wds-simple-page-builder' ),
'object_types' => array( 'post' ),
'context' => 'normal',
'priority' => 'high',
'show_names' => true,
) );
$group_field_id = $cmb->add_field( array(
'id' => $prefix . 'template',
'type' => 'group',
'options' => array(
'group_title' => esc_html__( 'Template Part {#}', 'wds-simple-page-builder' ),
'add_button' => esc_html__( 'Add another template part', 'wds-simple-page-builder' ),
'remove_button' => esc_html__( 'Remove template part', 'wds-simple-page-builder' ),
'sortable' => true
)
) );
$cmb->add_group_field( $group_field_id, array(
'name' => esc_html__( 'Template', 'wds-simple-page-builder' ),
'id' => 'template_group',
'type' => 'select',
'options' => wds_page_builder_get_parts()
) );
}
add_action( 'cmb2_init', array( $this, 'do_meta_boxes' ) );