add user to protected content membership in code

I am using protected content on my site, but am using a web hook to add users to the site via a hubspot account. I have written the code to add the user, but need to add the user to a specific membership.

Can you give me a clue as to what class I might load and what function I might call to add a user to a specific membership?

  • Tyler Postle

    Hey Nick,

    Hope you're doing well today! Thanks for your question.

    This is a above my level of coding, so I'll call in one of our SLS staff(coding experts) to provide more effective assistance for you :slight_smile:

    Would you be able to send the code you do have in so I can pass it on to them? Perhaps that might help them figure out the best route to go for you.

    You can send that in via our private contact form:

    Send in:

    Subject: "Attn: Tyler Postle"
    -custom code
    -link back to this thread for reference
    -any other relevant urls (if any)

    Select "I have a different question" for your topic - this and the subject line ensure that it gets assigned to me :slight_smile:

    Look forward to hearing back and hope you enjoy your weekend!

    All the best,

  • Jose

    Hi there @Nick,

    This should be quite straightforward. Most of the methods in Protected Content are static, so you don't even need to worry about scopes or instances.

    If I'm not missing anything, this is what you are looking for:

    //Creates the new member.
    $member = MS_Factory::load(
    $member->is_member = true;
    //Assign the member to a specific membership.

    Please let us know if this works for you.