Alright, I’ve hacked it up myself.
I changed the
In CMB2_Field.php, I changed the replace_hash function to be:
public function replace_hash($value)
{
if (!$this->options('group_title_callback')) {
// Replace hash with 1 based count
return str_ireplace('{#}', ($this->count() + 1) , $value);
}
else {
$fields = array();
foreach(array_values($this->args('fields')) as $field_args) {
$field = new CMB2_Field(array(
'field_args' => $field_args,
'group_field' => $this,
));
$fields[$field_args['id']] = $field->value;
}
return call_user_func($this->options('group_title_callback') , $fields);
}
}
Then in my metabox setup, I set:
'group_title' => 'New Widget',
'group_title_callback' => array($this, 'format_group_title'),
and finally my formatting callback that sets the title based off the field values:
public function format_group_title($fields) {
return $fields['time'] . ' ' . $fields['name'];
}
This results in new items having the title “New Widget”, and existing groups getting an informative title based off two fields.
It’s a bit of a hack, is there a way to do this without editing CMB2? I’d rather not break automatic updates and maintain my own fork.
Edit: improved slightly
As I mentioned in the subsequent pull request, this desired functionality will need to be a custom Javascript solution.
My only idea at this point involves filtering the gettext for the 3 spots, but I’m not sure that’s going to provide you enough to affect all the text you need, especially any that trickle down to other parts.
Have you ever done any work with WP Nav Walker extending? I’m curious if you can do a similar thing for the callback here.
Would love to see this implemented +1