Skip to content

Instantly share code, notes, and snippets.

@toluaddy
Forked from codelion7/sync_member_type.php
Created February 3, 2020 16:43
Show Gist options
  • Select an option

  • Save toluaddy/23e7167dc1051c8bfec8dd1b5e301551 to your computer and use it in GitHub Desktop.

Select an option

Save toluaddy/23e7167dc1051c8bfec8dd1b5e301551 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