Created
January 4, 2017 22:25
-
-
Save davidzack/ff0873c75e2c2acb4aa3fc1094c0df26 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//CREATE THE INTEREST TAXONOMY | |
//New Interest Taxonomy for Users | |
register_taxonomy('interest', 'user', array( | |
'public' =>true, | |
'single_value' => false, | |
'show_admin_column' => true, | |
'labels' =>array( | |
'name' =>'Interests', | |
'singular_name' =>'Interest', | |
'menu_name' =>'Interests', | |
'search_items' =>'Search Interests', | |
'popular_items' =>'Popular Interests', | |
'all_items' =>'All Interests', | |
'edit_item' =>'Edit Interest', | |
'update_item' =>'Update Interest', | |
'add_new_item' =>'Add New Interest', | |
'new_item_name' =>'New Interest Name', | |
'separate_items_with_commas' =>'Separate Interests with commas', | |
'add_or_remove_items' =>'Add or remove interests', | |
'choose_from_most_used' =>'Choose from the most popular interests', | |
), | |
'rewrite' =>array( | |
'with_front' =>true, | |
'slug' =>'interest', | |
), | |
'capabilities' => array( | |
'manage_terms' =>'edit_users', | |
'edit_terms' =>'edit_users', | |
'delete_terms' =>'edit_users', | |
'assign_terms' =>'read', | |
), | |
)); | |
//SAVE INTEREST TAXONOMY WHEN CREATING USER VIA GF | |
function map_taxonomy($user_id, $config, $entry, $user_pass) { | |
global $wpdb; | |
// Get all taxonomies | |
$taxs = get_taxonomies(); | |
// Get all user meta | |
$all_meta_for_user = get_user_meta($user_id); | |
// Loop through meta data and map to taxonomies with same name as user meta key | |
foreach ($all_meta_for_user as $taxonomy => $value ) { | |
if (in_array ($taxonomy, $taxs) ) { // Check if there is a Taxonomy with the same name as the Custom user meta key | |
// Get term id | |
$term_id = get_user_meta($user_id, $taxonomy, true); | |
If (is_numeric($term_id)) { // Check if Custom user meta is an ID | |
Echo $taxonomy.'='.$term_id.'<br>'; | |
// Add user to taxomomy term | |
$term = get_term( $term_id, $taxonomy ); | |
$termslug = $term->slug; | |
wp_set_object_terms( $user_id, array( $termslug ), $taxonomy, false); | |
} | |
} | |
} | |
} | |
add_action("gform_user_registered", "map_taxonomy", 10, 4); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment