Skip to content

Instantly share code, notes, and snippets.

@codelion7
Created August 10, 2017 05:48
Show Gist options
  • Save codelion7/2074e4962dbc0da80df60a7cb5dc20a6 to your computer and use it in GitHub Desktop.
Save codelion7/2074e4962dbc0da80df60a7cb5dc20a6 to your computer and use it in GitHub Desktop.
Sync BuddyPress Member Type to Another Blog on a Multisite Network
<?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