Skip to content

CMB2 no longer showing image field or any field declared after on local install #1074

@brothman01

Description

@brothman01

Expected Behavior:

Show all the fields in my post like before

Actual Behavior:

shows the first text field but does not show the second, third or fourth fields because CMB2 seems to break when trying to render the image field.

Steps to reproduce (I have confirmed I can reproduce this issue on the trunk branch):

I am not even sure how this happened. It just isn't working today but it has been working in this untouched plugin for a few months.

The post page displays this error in place of the image field:
Fatal error: Declaration of CMB2_Type_File::render() must be compatible with CMB2_Type_Text::render($args = Array) in /Users/ben/eFiles/valet/test-site/wp-content/plugins/BR-Staff/cmb2/includes/types/CMB2_Type_File.php on line 13

CMB2 Field Registration Code:

add_action( 'cmb2_admin_init', 'cmb2_sample_metaboxes' );
/**
 * Define the metabox and field configurations.
 */
function cmb2_sample_metaboxes() {
		$prefix = 'br_';

		/**
		 * Initiate the metabox
		 */
		$cmb = new_cmb2_box( array(
				'id'            => 'test_metabox',
				'title'         => __( 'Staff Member', 'cmb2' ),
				'object_types'  => array('br_person' ), // 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'       => __( 'Display Name', 'cmb2' ),
				'desc'       => __( '', 'cmb2' ),
				'id'         => $prefix . 'name',
				'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,
		) );

		$cmb->add_field( array(
			'name' => esc_html__( 'Portrait', 'cmb2' ),
			'desc' => esc_html__( 'Upload an image or enter a URL.', 'cmb2' ),
			'id'   => $prefix . 'portrait',
			'type' => 'file',
		) );

		// Regular text field
		$cmb->add_field( array(
				'name'       => __( 'Title', 'cmb2' ),
				'desc'       => __( '', 'cmb2' ),
				'id'         => $prefix . 'title',
				'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,
		) );

		$cmb->add_field( array(
			'name'    => esc_html__( 'Bio', 'cmb2' ),
			'desc'    => esc_html__( 'field description (optional)', 'cmb2' ),
			'id'      => $prefix . 'bio',
			'type'    => 'wysiwyg',
			'options' => array( 'textarea_rows' => 5, ),
		) );

		$cmb->add_field( array(
				'name'       => __( 'Shortcode', 'cmb2' ),
				'desc'       => __( '', 'cmb2' ),
				'id'         => $prefix . 'shortcode',
				'type'       => 'text',
				'show_on_cb' => 'cmb2_hide_if_no_cats', // function should return a bool value
				'default' => 'prefix_set_test_default',
		) );

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions