Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WPMU Membership assign membership based on role on registration
<?php
add_action( 'user_register', 'assign_membership_on_register', 10, 1 );
function assign_membership_on_register( $user_id ) {
$membership = array(
// 'role' => 'membership ID'
'abc' => 123,
'xyz' => 456
);
$user_meta = get_userdata( $user_id );
$user_roles = $user_meta->roles;
$member = MS_Factory::load( 'MS_Model_Member', $user_id );
$subscription = $member->add_membership( $membership[ $user_roles[0] ] );
if ( $member->has_membership() ) {
$member->is_member = true;
} else {
$member->is_member = false;
}
$member->save();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.