Created
July 1, 2015 18:09
-
-
Save greathmaster/ec938005b5e616470e77 to your computer and use it in GitHub Desktop.
Update Category Membership Level Restrictions for Foreign Languages In PMPro
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
/** | |
* | |
* @param int $save_id | |
* Updates equivalent membership category in other languages when saving levels. | |
* Not suitable for large number of languages. | |
*/ | |
function update_level_categories_for_all_languages($save_id) | |
{ | |
$level_cat_ids = pmpro_getMembershipCategories($save_id); | |
$updated_level_cat_ids = $level_cat_ids; | |
$all_languages = icl_get_languages(); | |
foreach($level_cat_ids as $key => $cc) | |
{ | |
foreach ($all_languages as $lang => $row) | |
{ | |
$term_id = icl_object_id($cc, 'category',false, $lang); | |
if($term_id && !in_array($term_id, $updated_level_cat_ids)) | |
{ | |
$updated_level_cat_ids[] = $term_id; | |
} | |
} | |
} | |
pmpro_updateMembershipCategories( $save_id, $updated_level_cat_ids ); | |
} | |
add_action("pmpro_save_membership_level", "update_level_categories_for_all_languages", 10); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi there, does this code get inserted to the functions.php file?