Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
brothman01 opened this issue Dec 16, 2017 · 2 comments

Comments

@brothman01
Copy link

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

}
@jtsternberg
Copy link
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.

@brothman01
Copy link
Author

Yes, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants