Skip to content

Commit

Permalink
This allows for complete groups to become conditional on fields.
Browse files Browse the repository at this point in the history
This presumes PR CMB2/CMB2#582 has been merged into CMB2.

Fixes jcchavezs#2.

The js side of things is working.

@todo Needs checking if any more filtering for saving needs to be done on the PHP side of things.
  • Loading branch information
jrfnl committed Feb 4, 2016
1 parent 1fb629a commit 0993c02
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cmb2-conditionals.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function cmb2_conditionals_load_actions()

add_action('admin_init', 'cmb2_conditionals_hook_data_to_save_filtering', CMB2_CONDITIONALS_PRIORITY);
add_action('admin_footer', 'cmb2_conditionals_footer', CMB2_CONDITIONALS_PRIORITY);
add_action('cmb2_additional_group_attributes', 'cmb2_conditionals_group_attributes', CMB2_CONDITIONALS_PRIORITY, 3);
}

/**
Expand All @@ -38,6 +39,18 @@ function cmb2_conditionals_footer()
wp_enqueue_script('cmb2-conditionals', plugins_url('/cmb2-conditionals.js', __FILE__ ), array('jquery'), '1.0.2', true);
}

function cmb2_conditionals_group_attributes( $attr_string, $group_args, $group_id ) {
if(!isset($group_args['attributes']['data-conditional-id'])) {
return $attr_string;
}

$attr_string .= ' data-conditional-id="'.esc_attr($group_args['attributes']['data-conditional-id']).'"';
if(isset($group_args['attributes']['data-conditional-value'])) {
$attr_string .= ' data-conditional-value="'.esc_attr($group_args['attributes']['data-conditional-value']).'"';
}
return $attr_string;
}

/**
* Hooks the filtering of the data being saved.
*/
Expand Down

0 comments on commit 0993c02

Please sign in to comment.