Created
August 10, 2017 05:48
-
-
Save codelion7/2074e4962dbc0da80df60a7cb5dc20a6 to your computer and use it in GitHub Desktop.
Sync BuddyPress Member Type to Another Blog on a Multisite Network
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
<?php | |
function sync_member_type( $user_id = 0 ) { | |
if ( empty( $user_id ) ) | |
$user_id = get_current_user_id(); | |
$memb_types = bp_get_member_type( $user_id, false ); | |
switch_to_blog( 3 ); | |
$count == 0; | |
foreach( $memb_types as $key => $type_name ) { | |
$count++; | |
if ( $count == 1 ) { | |
// Set the user's member type | |
bp_set_member_type( $user_id, $type_name ); | |
} elseif ( $count > 1 ) { | |
bp_set_member_type( $user_id, $type_name, true ); // Append additional member types | |
} | |
} | |
restore_current_blog(); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment