Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sunriseweb/6284799 to your computer and use it in GitHub Desktop.
Save sunriseweb/6284799 to your computer and use it in GitHub Desktop.
Profile Builder Pro plugin ntegration to Populate Custom Taxonomy Checkboxes
/** Replace the "hotbuy_regions" checkbox options with terms from the location taxonomy
* see http://www.cozmoslabs.com/forums/topic/checkbox-name-when-filtering-using-wppb_x_checkbox_custom_field_y/#post-19294
*/
add_action( 'create_term', 'replace_hotbuy_regions', 10, 3 );
add_action( 'edit_term', 'replace_hotbuy_regions', 10, 3 );
add_action( 'delete_term', 'replace_hotbuy_regions', 10, 3 );
function replace_hotbuy_regions($term_id, $tt_id, $taxonomy) {
if($taxonomy == 'locations') {
$args = array(
'hide_empty' => false,
);
$locations = get_terms($taxonomy, $args);
$termarray = array();
$namearray = array();
$parentarray = array();
$refarray = array();
foreach($locations as $location) {
$parentarray[$location->parent][$location->term_id] = $location->name;
$refarray[$location->term_id] = $location->name;
}
ksort($parentarray);
foreach($parentarray as $parent => $locarray) {
if($parent == 0) {
foreach($locarray as $term_id => $name) {
$termarray[] = $term_id;
$namearray[] = '<strong>'.$name.'</strong>';
if(is_array($parentarray[$term_id])) {
foreach($parentarray[$term_id] as $cterm_id => $cname) {
$termarray[] = $cterm_id;
$namearray[] = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$cname.'('.$name.')';
}
}
}
}
}
$pb_options = get_option('wppb_custom_fields');
if (is_array($pb_options)){
foreach ($pb_options as $key => $single_option){
if ( $single_option['item_metaName'] == 'hotbuy_regions' ) {
$pb_options[$key]['item_options'] = implode(',',$namearray);
$pb_options[$key]['item_option_values'] = implode(',',$termarray);
}
}
}
update_option('wppb_custom_fields', $pb_options);
}
}
/** Filter the Profile Builder Pro checkbox for locations to populate with location terms
* See http://www.cozmoslabs.com/docs/profile-builder-documentation/developer-docs/#Filters_applied_to_the_Extra_Custom_Fields_only
* wppb_X_checkbox_custom_field_Y
DEFINITION: A filter for the checkbox custom field.
RETURNS: 1 string-type variable.
TIP: Can be used to change/remove this custom field. X represents the page you want to affect (back_end, edit_profile and register), and Y represents the id (read from the back-end).
**/
add_filter('wppb_back_end_checkbox_custom_field_2', 'hotbuys_reformat_hotbuy_regions');
add_filter('wppb_register_checkbox_custom_field_2', 'hotbuys_reformat_hotbuy_regions');
add_filter('wppb_edit_profile_checkbox_custom_field_2', 'hotbuys_reformat_hotbuy_regions');
function hotbuys_reformat_hotbuy_regions($checkboxhtml) {
$newhtml = str_replace('<input', '<div><input', $checkboxhtml);
$newhtml = str_replace('</span>', '</span></div>', $newhtml);
$newhtml = str_replace('<span class="wppb-description-delimiter">', '<div><span class="wppb-description-delimiter">', $newhtml);
return $newhtml;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment