How to get CMB working within a plugin?

Community Forums Forums General Discussion How to get CMB working within a plugin?

This topic is: resolved

Tagged: , ,

This topic contains 1 reply, has 1 voice, and was last updated by  Posh John 7 months, 3 weeks ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #93296

    Posh John
    Participant
    Post count: 42

    I am in the process of moving my CPTs to a core functionality plugin (my first plugin yay!)

    I am having trouble getting my metaboxes to work within my plugin – i’m using the CMB files.

    Usually with my /lib/metabox folder inside my theme it works, but i can’t figure out how to move all this to the plugin. When i was building my cpt within my theme i had this in my cpt file >

    // Initialize the metabox class
    add_action( 'init', 'be_initialize_cmb_meta_boxes', 9999 );
    function be_initialize_cmb_meta_boxes() {
    	if ( !class_exists( 'cmb_Meta_Box' ) ) {
    		require_once(CHILD_DIR . '/lib/metabox/init.php');
    	}
    }
    

    Now i am doing it from within my plugin, I tried changing the “require_once” line to the following >
    require_once( plugin_dir_url(__file__) . 'lib/metabox/init.php' );

    … but get the white screen of death! What am i doing wrong?


    Thus the heavens and the earth were completed in all their vast array. Genesis 2

    • This topic was modified 7 months, 3 weeks ago by  Posh John. Reason: typo
    • This topic was modified 7 months, 3 weeks ago by  Posh John. Reason: typo
    #93443

    Posh John
    Participant
    Post count: 42

    Figured it out!

    For anyone that’s interested, the “require_once” line should have been >

    require_once( plugin_dir_path(__FILE__) . 'lib/metabox/init.php' );

    Cool – i just built my first plugin :-)


    Thus the heavens and the earth were completed in all their vast array. Genesis 2

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.