Skip to content

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

Closed

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',
		) );

}

Activity

  1. jtsternberg commented on Dec 16, 2017

    @jtsternberg
    Member

    This is because you have updated php to 7.2, and it is fixed in the trunk branch. See #1070. This is why we put the "(I have confirmed I can reproduce this issue on the trunk branch)" in the issue description, because it may often solve your problem before you need to report it.

  2. brothman01 commented on Dec 16, 2017

    @brothman01
    Author

    Yes, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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