Support » Plugin: CMB2 » separation example-function.php file

  • Resolved theme2021

    (@theme2021)


    How can I break down the code inside this file (example-function.php) ? since I have about 600 lines and it is difficult to find the section I need, I would like to split the code so that each box is in a separate file, is it possible ?

    • This topic was modified 7 months, 2 weeks ago by theme2021.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Michael Beckwith

    (@tw2113)

    The BenchPresser

    you don’t need to create all your metaboxes in one single callback to cmb2_admin_init. You could create one callback per file, that has just one metabox invocation each.

    first_file.php

    add_action( 'cmb2_admin_init', 'yourprefix_register_first' );
    function yourprefix_register_first() {
    
    	$cmb_term = new_cmb2_box( array(
    		'id'               => 'yourprefix_term_edit',
    		'title'            => esc_html__( 'Category Metabox', 'cmb2' ), // Doesn't output for term boxes
    		'object_types'     => array( 'term' ), // Tells CMB2 to use term_meta vs post_meta
    		'taxonomies'       => array( 'category', 'post_tag' ), // Tells CMB2 which taxonomies should have these fields
    		// 'new_term_section' => true, // Will display in the "Add New Category" section
    	) );
    
    }
    

    second_file.php

    add_action( 'cmb2_admin_init', 'yourprefix_register_second' );
    function yourprefix_register_second() {
    
    	$cmb_term = new_cmb2_box( array(
    		'id'               => 'yourprefix_term_edit',
    		'title'            => esc_html__( 'Category Metabox', 'cmb2' ), // Doesn't output for term boxes
    		'object_types'     => array( 'term' ), // Tells CMB2 to use term_meta vs post_meta
    		'taxonomies'       => array( 'category', 'post_tag' ), // Tells CMB2 which taxonomies should have these fields
    		// 'new_term_section' => true, // Will display in the "Add New Category" section
    	) );
    
    }
    

    third_file.php

    add_action( 'cmb2_admin_init', 'yourprefix_register_third' );
    function yourprefix_register_third() {
    
    	$cmb_term = new_cmb2_box( array(
    		'id'               => 'yourprefix_term_edit',
    		'title'            => esc_html__( 'Category Metabox', 'cmb2' ), // Doesn't output for term boxes
    		'object_types'     => array( 'term' ), // Tells CMB2 to use term_meta vs post_meta
    		'taxonomies'       => array( 'category', 'post_tag' ), // Tells CMB2 which taxonomies should have these fields
    		// 'new_term_section' => true, // Will display in the "Add New Category" section
    	) );
    
    }
    
    Thread Starter theme2021

    (@theme2021)

    Thank you!

    Plugin Author Michael Beckwith

    (@tw2113)

    The BenchPresser

    Welcome.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘separation example-function.php file’ is closed to new replies.