Accessing CMB2 data structures inside filters
-
I am having considerable difficulty accessing CMB2 data structures inside a WordPress filter. I have a function of the form:
$options = new_cmb2_box($args); $options = apply_filters ('my_filter', $options );Inside the filter, I’m finding the $options array to be uncountable and I’m having difficulty with call by value vs. call by reference. My filter needs to be able to add, modify, and remove fields from the metabox.
I’ve tried defining it both as:
function my_filter($box)and
function my_filter(& $box)with no real success. I’m able to call:
$box->remove_field("my_field");but I’ve been unable to call:
$box->add_field(array( 'id' => 'id_value', [more items], ));I’m getting errors of the form “Warning: Parameter 1 to my_filter() expected to be a reference, value given in /app/public/wp-includes/class-wp-hook.php on line 288” and so on.
What’s the right way to manipulate the contents and specification of a metabox within a WordPress filter? Any examples would help.
Thanks!
The topic ‘Accessing CMB2 data structures inside filters’ is closed to new replies.