Skip to content

The current_object_type() method does not resolve correctly for a metabox that has multiple values for the 'object_types' attribute when called from the 'admin-ajax.php' page context #841

@ADC07

Description

@ADC07

Expected Behavior:

For taxonomy-term based metaboxes that have multiple object-types, the field data should be persisted when called upon via admin-ajax.php from within the Add New Tag form of the edit-tags.php page.

Actual Behavior:

The field data does not get saved due to the fact that the mb_object_type() method is used to determine the metabox's object-type based on which program execution flow is determined; the aforementioned method relies upon current_object_type() method that returns an invalid object-type (the default post) instead of the expected term object-type and therefore the program execution flow goes down a different path and registers the post-related hooks instead of term-related hooks and so forth.

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

  1. Register a taxonomy-term type metabox using the code depicted below;
  2. Navigate to the relevant taxonomy page and fill in the metabox field;
  3. Click the Add New Tag button and check the resulting term's field value.

CMB2 Field Registration Code:

add_action( 'cmb2_admin_init', 'yourprefix_register_demo_metabox' );
function yourprefix_register_demo_metabox() {

    $cmb = new_cmb2_box( array(
	'id'            => 'cot_test_metabox',
	'title'         => __( 'Test Metabox', 'cmb2' ),
	'object_types'  => array( 'term', 'page' ),
	'taxonomies'	=> 'cot_test_taxonomy'
    ) );

    $cmb->add_field( array(
	'name'       => __( 'Test Text', 'cmb2' ),
	'id'         => 'cot_test_field',
	'type'       => 'text',
    ) );

}

register_taxonomy('cot_test_taxonomy', 'page');

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