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):
- Register a taxonomy-term type metabox using the code depicted below;
- Navigate to the relevant taxonomy page and fill in the metabox field;
- 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');