When you say update the options, you mean update what ends up stored in that $sites variable?
How are you populating the variable in the first place? Custom function call? Static list that you change each time needed? Somehow else?
Hi`Hello,
thank you very much for the answer.
I create the custom field as follows:
add_action( 'cmb2_admin_init', 'cmb2_metaboxes' );
/**
* Define the metabox and field configurations.
*/
function cmb2_metaboxes() {
/**
* Initiate the metabox
*/
$cmb = new_cmb2_box( array(
'id' => 'vlck_syncbox',
'title' => 'Synchronisation - Einstellungen',
'object_types' => array( 'post', ), // Post type
'context' => 'normal',
'priority' => 'high',
'show_names' => true,
) );
$sites = [];
$sitesOption = get_option( 'wp_api_mcs_sites' );
if ( $sitesOption ) {
foreach ( $sitesOption as $url => $site ) {
$sites[ $url ] = $url;
}
}
$fieldId = $cmb->add_field( array(
'name' => 'Ziele',
'desc' => 'Ziele mit denen dieser Beitrag synchronisiert werden soll.',
'id' => 'vlck_field_sync_to',
'type' => 'multicheck',
'options' => $sites,
) );
if ( $fieldId ) {
add_option( 'vlck_sync_field_id', $fieldId );
}
}
I then need to adjust the available options of the Custom Field in another method from time to time. For example, at the beginning I have only two check boxes in the multi-checkbox field, but later I need three or even four
From what I’m seeing, everything in this checkbox field is dependent on the data stored in the wp_api_mcs_sites option, which I assume CMB2 has zero control over, so there’s not really much we can do with that beyond what you’re already doing.
The only way I can think of would be if there’s perhaps an API endpoint or something that’s being used for setting/saving the values in the option. Instead of storing to an option, just make the API request directly here and grab the desired parts at that moment. I know we have an options_cb where cb means callback, you could specify a function to invoke directly with it.
https://github.com/CMB2/CMB2/wiki/Field-Types#optional