• Resolved wyoung221

    (@wyoung221)


    I got hired to do some ecommerce stuff for a company but I’m dumb as hell and they want me to run the whole website. Currently it has jquery.fn.live errors that pop up when Foogallery is activated and I think I’ve tracked them down to the CMB version 0.9 that is in the mu-plugins\core-functionality folder. Deleting init.php entirely breaks everything, but I don’t know what I am supposed to replace with CMB2 or what the guy who first installed it may have changed in CMB. Every Readme I’ve found just says “put it here and make sure init.php is there too” but I don’t know where the customization actually takes place so I have no clue how to make whatever options were set for CMB to be the same for CMB2. Is there a way to migrate from CMB to CMB2 for people who’s coding experience starts and stops with copy/paste?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    It won’t be super comprehensive but I know we have https://github.com/CMB2/CMB2/wiki/Notable-Changes-in-CMB2 and then just https://github.com/CMB2/CMB2/wiki as a whole.

    The real question is where is your current configuration for it all and what state is it in.

    If it’s really that old enough, doing a search for cmb_ on the files may get you there right away.

    One thing will say is that changing the configurations should not affect the data stored, as that’s all going to be in your wp_postmeta table. CMB/CMB2 is more a library to wire up metaboxes and display that content.

    As is, I suspect there’s probably a file or two somewhere in that core-functionality folder that is doing an add_filter on cmb2_meta_boxes and constructing a big array of fields.

    https://github.com/CMB2/CMB2/blob/develop/example-functions.php will be a good file to check out as it has a lot of copy/pasteable examples of how to best work with CMB2 now.

    Thread Starter wyoung221

    (@wyoung221)

    Yep you were right, there was a metaboxes.php file that said add_filter( 'cmb_meta_boxes' , 'be_metaboxes' ); and then a bunch of arrays. I deleted the file and it removed some fields, but I don’t think they’re even used for anything. If I’m wrong, I guess I’ll be back another day because I tried everything I could think to make the metaboxes.php work with CMB2 but it only made things worse. Thank you for your help!

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Not sure I would have gone and deleted it because it would provide a lot of useful information if you’re wanting/needing to convert to CMB2. Specifically the ID values being passed in, as those represent the meta keys.

    At this point, I’d end up using that file as a map for what field types to create with the CMB2 method of creating metaboxes and https://github.com/CMB2/CMB2/wiki/Field-Types

    Thread Starter wyoung221

    (@wyoung221)

    I have the file saved and I’ve only deleted it from Staging at the moment. I tried to update all the CMBs to CMB2s, change Pages to Object_Types, cut the “Notable Change 3” part about including core files, add the bootstrap section, and replaced the whole cmb folder with cmb2, but I’m missing something because as long as the metaboxes.php file exists, it gives the site a critical error. I’ve spent a week on this and the site not being broken is a victory, even if those fields are now gone. It is probably a very simple thing to fix, but I’m so bad with coding that this is the equivalent of a expecting a caveman to put together an internal combustion engine when he’s barely figured out the concept of fire. I really appreciate the help you’ve given me

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    what’s the critical error that’s occurring? I may be able to help resolve that one.

    Thread Starter wyoung221

    (@wyoung221)

    Well I think I finally figured out why these boxes were ever made in the first place: the only thing that has the ids that are in the metaboxes file is an old theme that isn’t in use anymore, so I believe it is fully deprecated and I’m ready to wash my hands of it. Again, thank you very much, you pointed me in directions I never would’ve looked and this would’ve taken me days of frustration otherwise. I already typed out everything below before I figured that out though so if you’re curious:

    PHP Fatal error: Uncaught Error: Call to a member function add_field() on array in /nas/content/staging/[site]/wp-content/mu-plugins/core-functionality/functions/metaboxes.php:40
    Stack trace:
    #0 /nas/content/staging/[site]/wp-includes/class-wp-hook.php(287): be_metaboxes(Array)
    #1 /nas/content/staging/[site]/wp-includes/plugin.php(206): WP_Hook->apply_filters(Array, Array)
    #2 /nas/content/staging/[site]/wp-content/plugins/cmb2/bootstrap.php(42): apply_filters('cmb2_meta_boxes', Array)
    #3 /nas/content/staging/[site]/wp-content/plugins/cmb2/init.php(165): cmb2_bootstrap()
    #4 /nas/content/staging/[site]/wp-includes/class-wp-hook.php(287): CMB2_Bootstrap_270->include_cmb('')
    #5 /nas/content/staging/[site]/wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters(NULL, Array)
    #6 /nas/content/staging/[site]/wp-includes/plugin.php(478): WP_Hook->do_action(Array)
    #7 /nas/content/staging/[site]/wp-settings.php(546): do_action('init')
    #8 /nas/content/staging/[site]/nas/content/staging/[site]/wp-content/mu-plugins/core-functionality/functions/metaboxes.php on line 40, referer: https://[mysite].staging.wpengine.com/wp-admin/

    Line 40 is $meta_boxes->add_field( array( and for context, below is how the first few sections of metaboxes.php are set up. I suspect that, probably among other things, the ‘fields’ => array is wrong because I don’t see that anywhere in the guides; I’m guessing it was done this way to group them together but I can’t make heads or tails of how to change it.

    add_filter( 'cmb2_meta_boxes' , 'be_metaboxes' );
    /**
     * Create Metaboxes
     * @since 1.0.0
     * @link https://www.billerickson.net/wordpress-metaboxes/
     */
    
    function be_metaboxes( $meta_boxes ) {
    
    	$meta_boxes->add_field( array(
    		'id' => 'product-information',
    		'title' => 'Product Information',
    		'object_types' => array( 'product' ),
    		'context' => 'normal',
    		'priority' => 'high',
    		'show_names' => true,
    		'fields' => array(
    			array(
    				'name' => 'The Details',
    				'desc' => '',
    				'id' => 'be_product_details',
    				'type' => 'wysiwyg',
    				'options' => array(
    					'textarea_rows' => 5,
    				)
    			),
    			array(
    				'name' => 'The Fit',
    				'desc' => '',
    				'id' => 'be_product_fit',
    				'type' => 'wysiwyg',
    				'options' => array(
    					'textarea_rows' => 5,
    				)
    			),
    			array(
    				'name' => 'Set Page Background to Non-White',
    				'desc' => '',
    				'id' => 'be_product_white_bg',
    				'type' => 'checkbox',
    			)
    			
    		)
    	));
    	$meta_boxes->add_field( array(
    		'id' => 'archive-information',
    		'title' => 'Archive Information',
    		'object_types' => array( 'product' ),
    		'context' => 'normal',
    		'priority' => 'high',
    		'show_names' => true,
    		'fields' => array(
    			array(
    				'name' => 'Title',
    				'desc' => 'Used on category and related post listings. If not provided, defaults to page title',
    				'id' => 'be_archive_title',
    				'type' => 'text',
    			),
    			array(
    				'name' => 'Description',
    				'desc' => 'Used on category and related post listings. If not provided, defaults to Summary from Product Information.',
    				'id' => 'be_archive_desc',
    				'type' => 'wysiwyg',
    				'options' => array(
    					'textarea_rows' => 2,
    				),
    			),
    
    		)
    	));
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    No worries all in all.

    As a quick example, though, in case you’re curious. The code below would be the current equivalent for the “Product Information” metabox from your code:

    function yourprefix_register_demo_metabox() {
    	$cmb_demo = new_cmb2_box( array(
    		'id'            => 'product-information',
    		'title'         => 'Product Information',
    		'object_types' => array( 'product' ),
    		'context' => 'normal',
    		'priority' => 'high',
    		'show_names' => true,
    	) );
    
    	$cmb_demo->add_field( array(
    		'name'       => 'The Details',
    		'desc'       => '',
    		'id'         => 'be_product_details',
    		'type'       => 'wysiwyg',
    		'options'    => array(
    			'textarea_rows' => 5,
    		)
    	) );
    
    	$cmb_demo->add_field( array(
    		'name'       => 'The Fit',
    		'desc'       => '',
    		'id'         => 'be_product_fit',
    		'type'       => 'wysiwyg',
    		'options'    => array(
    			'textarea_rows' => 5,
    		)
    	) );
    
    	$cmb_demo->add_field( array(
    		'name' => 'Set Page Background to Non-White',
    		'desc' => '',
    		'id' => 'be_product_white_bg',
    		'type' => 'checkbox',
        ) );
    }
    add_action( 'cmb2_admin_init', 'yourprefix_register_demo_metabox' );
    
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Idiots guide to migrate from CMB .09 to CMB2’ is closed to new replies.