Support » Plugin: CMB2 » Something stupid

  • Resolved napalmx37

    (@napalmx37)


    Apologies for the stupid question, but, I have a site running a child theme.
    For some reason even the basic usage from the wiki, isn’t working. My meta box simply doesn’t show? What am I doing wrong?

    functions.php

    <?php
    // Exit if accessed directly
    
    add_action( 'cmb2_admin_init', 'cmb2_sample_metaboxes' );
    /**
     * Define the metabox and field configurations.
     */
    function cmb2_sample_metaboxes() {
    
    	/**
    	 * Initiate the metabox
    	 */
    	$cmb = new_cmb2_box( array(
    		'id'            => 'test_metabox',
    		'title'         => __( 'Test Metabox', 'cmb2' ),
    		'object_types'  => array( 'page', ), // Post type
    		'context'       => 'normal',
    		'priority'      => 'high',
    		'show_names'    => true, // Show field names on the left
    		// 'cmb_styles' => false, // false to disable the CMB stylesheet
    		// 'closed'     => true, // Keep the metabox closed by default
    	) );
    
    	// Regular text field
    	$cmb->add_field( array(
    		'name'       => __( 'Test Text', 'cmb2' ),
    		'desc'       => __( 'field description (optional)', 'cmb2' ),
    		'id'         => 'yourprefix_text',
    		'type'       => 'text',
    		'show_on_cb' => 'cmb2_hide_if_no_cats', // function should return a bool value
    		// 'sanitization_cb' => 'my_custom_sanitization', // custom sanitization callback parameter
    		// 'escape_cb'       => 'my_custom_escaping',  // custom escaping callback parameter
    		// 'on_front'        => false, // Optionally designate a field to wp-admin only
    		// 'repeatable'      => true,
    	) );
    
    	// URL text field
    	$cmb->add_field( array(
    		'name' => __( 'Website URL', 'cmb2' ),
    		'desc' => __( 'field description (optional)', 'cmb2' ),
    		'id'   => 'yourprefix_url',
    		'type' => 'text_url',
    		// 'protocols' => array('http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet'), // Array of allowed protocols
    		// 'repeatable' => true,
    	) );
    
    	// Email text field
    	$cmb->add_field( array(
    		'name' => __( 'Test Text Email', 'cmb2' ),
    		'desc' => __( 'field description (optional)', 'cmb2' ),
    		'id'   => 'yourprefix_email',
    		'type' => 'text_email',
    		// 'repeatable' => true,
    	) );
    
    	// Add other metaboxes as needed
    
    }
    
    if ( !defined( 'ABSPATH' ) ) exit;
    // BEGIN ENQUEUE PARENT ACTION
    // AUTO GENERATED - Do not modify or remove comment markers above or below:
    
    if ( !function_exists( 'chld_thm_cfg_locale_css' ) ):
        function chld_thm_cfg_locale_css( $uri ){
            if ( empty( $uri ) && is_rtl() && file_exists( get_template_directory() . '/rtl.css' ) )
                $uri = get_template_directory_uri() . '/rtl.css';
            return $uri;
        }
    endif;
    add_filter( 'locale_stylesheet_uri', 'chld_thm_cfg_locale_css' );
             
    if ( !function_exists( 'child_theme_configurator_css' ) ):
        function child_theme_configurator_css() {
            wp_enqueue_style( 'chld_thm_cfg_child', trailingslashit( get_stylesheet_directory_uri() ) . 'style.css', array(  ) );
        }
    endif;
    
    // // END ENQUEUE PARENT ACTION
    
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Michael Beckwith

    (@tw2113)

    The BenchPresser

    first thing, JUST in case, make sure you’re editing a page.

    Second and only thing really standing out to me, would be this line of code on line 60:

    if ( !defined( 'ABSPATH' ) ) exit;
    

    Usually something like this is at the very top of the page, not the middle, and I’m curious if it’s having unintended side effects in that position. Though testing things out locally shows even that in that position didn’t stop it for me.

    Otherwise, no reason I can see why this wouldn’t show you SOMETHING.

    Thread Starter napalmx37

    (@napalmx37)

    Thanks – it’s working. Seems to have been a caching issue

    Plugin Author Michael Beckwith

    (@tw2113)

    The BenchPresser

    Interesting but glad you’re up and at ’em with this.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.