• Resolved Head Goldfish

    (@shoelaced)


    I realize this is a beta version so maybe there’s more that needs to be done, but I swear I have tried everything and the meta boxes don’t show up in the editor. I was using the old version until WordPress told me that it wasn’t a valid plugin and deleted it, and all my fields vanished. I followed the installation instructions to the letter. I uploaded it to a cmb2 directory in my plugins folder, I activated it in WordPress, I moved the example-functions.php outside of the cmb2 directory — no luck. Then I tried starting over and installing it from here and doing the same thing, in case this was a different version than the GitHub one — no luck. Then I opened up the example-functions.php and discovered that it was trying to include cmb/init.php instead of cmb2/init.php so I changed that and tried again. No luck. I tried leaving the example-functions.php in the cmb2 folder and changing it to include just ‘init.php’ — no luck. I tried moving the example-functions.php to my theme directory and changing the path again for ‘init.php’ — no luck. I tried installing the whole thing to my theme directory — no luck. I tried adding it to my functions.php but it doesn’t allow includes. It won’t show up on my Pages but I’ve tried changing the post type — no luck. It doesn’t show up in the Screen Options either, as the old one used to. Please tell me what I’m doing wrong and please update the installation instructions if they’re not accurate.

    https://www.ads-software.com/plugins/cmb2/

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

    (@tw2113)

    The BenchPresser

    This may be a multi-part reply as I’m new to CMB2 as well, so all patience is appreciated. This is because I’m also talking with Justin, the primary developer, to make sure I’m getting things accurate.

    One of the biggest things is that CMB2 is not directly an upgrade from the original CMB class. It’s a new implementation from scratch based on the original one. This time, we have made it into a “proper” plugin that you can install via the WP Plugin installer, and it provides all of the code for the new version. Just to be certain, you now have this as part of your folder structure?

    wp-content/plugins/cmb2/

    Making sure it’s directly in the plugins directory and not nested inside a different folder you may have in your plugins directory.

    WordPress saying something’s not a plugin and deleting it is sounding really odd and not like WordPress’ behavior.

    You shouldn’t need to do any cmb/cmb2 init loading with this new version because it’s happening automatically inside the cmb2 plugin. You should be able to remove any self-implemented lines for that at this point.

    Have you tried moving the example-functions.php file into your theme folder or a directory in it, and loading that from your functions.php file?

    Did you make sure to change the filter name from cmb_meta_boxes to cmb2_meta_boxes? We changed the hook for this new version, and it temporarily breaks compatibility until the hook can be changed.

    Example of what can be added to your functions.php to declare some with CMB2

    add_filter( 'cmb2_meta_boxes', 'cmb2_sample_metaboxes' );
    /**
     * Define the metabox and field configurations.
     *
     * @param  array $meta_boxes
     * @return array
     */
    function cmb2_sample_metaboxes( array $meta_boxes ) {
     	return $meta_boxes;
    }

    Hope that helps, but if you’ve tried everything above and are still struggling, I’ll keep helping to see what’s going on ??

    Thread Starter Head Goldfish

    (@shoelaced)

    Okay, I haven’t tested all of it but it appears that this worked! Yes I installed CMB2 fresh. The old one was working perfectly and then all of a sudden WordPress gave me an error on the plugins page and it all vanished, even though the old files were still in my plugin folder. I agree that it’s strange but in any case, I deleted the old files completely and installed the CMB2 plugin from WordPress. Then I followed your lead, deleted the require for init.php from the example-functions.php, and added everything else in that file to my theme’s functions.php.

    I think what I wasn’t clear on was that I had to add the example-functions to my theme’s functions, because it sounded like I could keep those two documents separate, and also that I had to remove the requre for init.php if installing as a plugin.

    Thank you for your quick reply! I’m setting this up for a client so I’ll be glad to get moving again.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Technically, it doesn’t NEED to go in your theme/theme’s functions.php. It just needs to go in a file that is loaded via WordPress, whether that be a custom plugin, or a custom file in a theme and that file is loaded by the theme, or if just directly in the functions.php file itself.

    Somehow, the add_filter/callback needs to be run with WordPress, and it should work.

    Regardless, you have it figured out for the time being, and that’s awesome. Let us know if you have any other questions and we’ll get them answered the best we can.

    I was already running CMB2, but not as a plugin. I just installed the plugin and got everything working just fine. Here’s what I did:

    1. Installed the plugin through the Plugin manager as you would any other plugin.
    2. Removed the /cmb directory I had within my theme file
    3. Removed the require_once 'cmb2/init.php'; line in my functions.php file

    I left everything else in place (the custom boxes I had made) and they’re all still working. Hope this helps someone.

    P.S. – it probably wouldn’t hurt to backup your theme just in case ??

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Justin’s goal is essentially to decouple CMB from being a set of files you manually include yourself in your own theme or plugin, and make it a standalone plugin that is active. Everything else is able to hook into it from wherever they need to, be it a theme or a custom plugin.

    gunness

    (@gunness)

    Hi Michael,

    thank you and your team for the work.

    I have the same problem, I can′t get it to work.

    what I`ve done so far:

    1. from my WordPress backend: install the plug in via www.ads-software.com (Version 2.0.0.1)

    2. in the wp-content/plugins/cmb2 folder: duplicate the example-functions.php and put that file in my themes folder.

    3. deleted the:

    /**
     * Get the bootstrap! If using the plugin from www.ads-software.com, REMOVE THIS!
     */
    if ( file_exists(  __DIR__ .'/cmb2/init.php' ) ) {
    	require_once  __DIR__ .'/cmb2/init.php';
    } elseif ( file_exists(  __DIR__ .'/CMB2/init.php' ) ) {
    	require_once  __DIR__ .'/CMB2/init.php';
    }

    in the example-functions.php in my theme folder.

    4. now I thought I see a metabox titled ?Text Metabox“ on all of my pages

    https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/wiki/Basic-Usage”

    – unfortunately nothing happened.

    can you please give me tip what i`am doing wrong.

    thank you very much!

    gunness

    Thread Starter Head Goldfish

    (@shoelaced)

    @gunness:

    I had to copy/paste everything in the example-functions.php and put it all in my functions.php to get it to work. I think there’s a way to tell the example-functions.php file to load while keeping it separate but I never figured it out.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    This should all be what you need, as a quick example. A custom function declared and used with the appropriate cmb2_meta_boxes hook:

    function cmb2_sample_metaboxes( array $meta_boxes ) {
    
    	// Start with an underscore to hide fields from custom fields list
    	$prefix = '_cmb2_';
    
    	$meta_boxes['test_metabox'] = array(
    		'id'            => 'test_metabox',
    		'title'         => __( 'Test Metabox', 'cmb2' ),
    		'object_types'  => array( 'post', ), // Post type
    		'context'       => 'normal',
    		'priority'      => 'high',
    		'show_names'    => true, // Show field names on the left
    		'fields'        => array(
    			array(
    				'name'       => __( 'Test Text', 'cmb2' ),
    				'desc'       => __( 'field description (optional)', 'cmb2' ),
    				'id'         => $prefix . 'test_text',
    				'type'       => 'text'
    			)
    		)
    	);
    
    	return $meta_boxes;
    }
    add_filter( 'cmb2_meta_boxes', 'cmb2_sample_metaboxes' );

    Once you have it added to your functions.php, the metabox should appear on the post post type, and when saved, the post meta key is going to be _cmb2_test_text. That’s the key you’ll use with the get_post_meta() call.

    gunness

    (@gunness)

    Hi,

    @shoelaced and

    @michael Beckwith

    it works now – I appreciate your help with this, thank you very much!

    regards

    gunness

    Hi, I know the last post to this issue was a while ago now, but I am having the same issue and am wondering if the above still applies or if the documentation has been amended?

    I have followed the documentation on this page: https://github.com/WebDevStudios/CMB2/wiki/Basic-Usage
    but cannot get it to work. I have gone through this post and tried all of the suggestions and still nothing.

    Can someone confirm whether the following code is needed?

    if ( file_exists( __DIR__ . ‘/cmb2/init.php’ ) ) {
    require_once __DIR__ . ‘/cmb2/init.php’;
    } elseif ( file_exists( __DIR__ . ‘/CMB2/init.php’ ) ) {
    require_once __DIR__ . ‘/CMB2/init.php’;
    }

    and also whether the cmb2 folder should be installed in the theme folder or the plugin folder. Documentation says theme, installation page on wordpress says plugin.

    please help.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    If you’re installing CMB2 as a standalone plugin via the www.ads-software.com repo here, the file exists checks above won’t be needed.

    If you’re using CMB2 as a standalone library that’s shipped with your own plugin or theme, then you will need to do your own loading of the init.php file as shown above, matching the paths correctly.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Tried and tried, can't get it to work.’ is closed to new replies.