I have a class that I am using as part of the CMB2 framework for WordPress. It has a protected object that I am trying to append a list of years to. My code looks like this in my function
function cmb2_team_members_metaboxes() {
global $redux_rg;
$prefix = '_cmb2_';
$cmb_team_members = new_cmb2_box(array(
'id' => 'team_member_metabox',
'title' => __( 'Team Member Metabox', 'rev-group' ),
'object_types' => array( 'post_type_teammember', ), // Post type
'context' => 'normal', // 'normal', 'advanced', or 'side'
'priority' => 'high', // 'high', 'core', 'default' or 'low'
'show_names' => true, // Show field names on the left
));
I add more fields then below I am trying to append the years()
output to an options list of an HTML select / dropdown. to do this I need to append $cmb_team_members->meta_box['fields']['_cmb_start_year']['options']
with the output array from the function years()
. Below is where I am trying to extend CMB2
class which is protected with the years()
output.
class yearsClass extends CMB2
{
public function __set($name, $value)
{
$this->$cmb_team_members->meta_box['fields']['_cmb_start_year']['options'] = years();
}
}
I know I am doing this completely wrong but I can’t seem to crack this. Any help would be appreciated.
I have years defined in my functions.php file and it outputs:
array(
2015 => 2015,
2014 => 2014
)
When I output the CMB2 Object I get this:
CMB2 Object (
[cmb_id:protected] => team_member_metabox
[meta_box:protected] => Array
(
[id] => team_member_metabox
[title] => Team Member Metabox
[type] =>
[object_types] => Array
(
[0] => post_type_teammember
)
[context] => normal
[priority] => high
[show_names] => 1
[show_on_cb] =>
[show_on] => Array
(
)
[cmb_styles] => 1
[enqueue_js] => 1
[fields] => Array
(
[_cmb2_division] => Array
(
[name] => Division
[desc] => The division of the company this person works in (These can be edited in the Revolution Group theme options)
[id] => _cmb2_division
[type] => select
[options] => Array
(
)
)
[_cmb2_photo] => Array
(
[name] => Photo
[desc] =>
[id] => _cmb2_photo
[type] => file
)
[_cmb2_position] => Array
(
[name] => Position
[desc] => Job position
[id] => _cmb2_position
[type] => text
)
[_cmb2_email] => Array
(
[name] => Email
[desc] => Email address
[id] => _cmb2_email
[type] => text_email
)
[_cmb2_bio] => Array
(
[name] => Bio
[desc] =>
[id] => _cmb2_bio
[type] => wysiwyg
[options] => Array
(
[media_buttons] => 1
[textarea_rows] => 5
)
)
[_cmb2_start_year] => Array
(
[name] => Year Started
[desc] => The year the team member started with Revolution Group
[id] => _cmb2_start_year
[type] => select
[options] => Array
(
)
)
[_cmb2_certifications_repeat_group] => Array
(
[id] => _cmb2_certifications_repeat_group
[type] => group
[description] => Certifications (These can be edited in the Revolution Group theme options)
[options] => Array
(
[group_title] => Certification {#}
[add_button] => Add Another Certification
[remove_button] => Remove Certification
[sortable] => 1
)
[fields] => Array
(
[certification] => Array
(
[name] => Certification
[description] => Please select
[id] => _cmb2_certification
[type] => select
[options] => Array
(
)
)
[certification_year] => Array
(
[name] => Year Obtained
[description] => The year this certification was aquired
[id] => _cmb2_certification_year
[type] => select
[options] => Array
(
)
)
)
)
[_cmb2_skills_repeat_group] => Array
(
[id] => _cmb2_skills_repeat_group
[type] => group
[description] => Skills (These can be edited in the Revolution Group theme options)
[options] => Array
(
[group_title] => Skill {#}
[add_button] => Add Another Skill
[remove_button] => Remove Skill
[sortable] => 1
)
[fields] => Array
(
[skill] => Array
(
[name] => Skill
[description] => Please select
[id] => _cmb2_skill
[type] => select
[options] => Array
(
)
)
)
)
[_cmb2_fun_fact] => Array
(
[name] => Fun Fact
[desc] =>
[id] => _cmb2_fun_fact
[type] => wysiwyg
[options] => Array
(
[media_buttons] => 1
[textarea_rows] => 5
)
)
[_cmb2_order] => Array
(
[name] => Order
[desc] => Order that the team member should be displayed. The lower the number the hghter on the list when displayed
[id] => _cmb2_order
[type] => text
)
)
[hookup] => 1
[save_fields] => 1
[closed] =>
[new_user_section] => add-new-user
)
[object_id:protected] => 0
[object_type:protected] => post
[mb_object_type:protected] => post
[updated:protected] => Array
(
)
[mb_defaults:protected] => Array
(
[id] =>
[title] =>
[type] =>
[object_types] => Array
(
)
[context] => normal
[priority] => high
[show_names] => 1
[show_on_cb] =>
[show_on] => Array
(
)
[cmb_styles] => 1
[enqueue_js] => 1
[fields] => Array
(
)
[hookup] => 1
[save_fields] => 1
[closed] =>
[new_user_section] => add-new-user
)
[fields:protected] => Array
(
)
[hidden_fields:protected] => Array
(
)
[data_to_save] => Array
(
)
[generated_nonce:protected] =>
)