trigger when a new member is created

If I put my custom code in the middle there, this will trigger when a new member is created? and "$instance" will give me that new users registration info?

// define the ms_model_member_create_new_user callback
function action_ms_model_member_create_new_user( $instance ) {
// make action magic happen here...
}; 

// add the action
add_action( 'ms_model_member_create_new_user', 'action_ms_model_member_create_new_user', 10, 1 );
  • Ash

    Hello there

    this will trigger when a new member is created?

    Yes, correct :slight_smile:

    and "$instance" will give me that new users registration info?

    Yeah, $instance will give you an instance of MS_Model_Member class for that specific user. You can check the class to know about the properties and methods :slight_smile:

    Hope it helps! Please feel free to ask more questions if you have any.

    Have a nice day!

    Cheers,
    Ash

  • mediastead

    Ash,

    I found this code, and it looks good, however, I have two memberships, and two courses. Each course belongs to a specific membership level, so I would also have to pull what membership level a person chooses, so I can enroll them in the correct course for their membership level.

    Does this make sense?

    add_action('user_register', 'coursepress_custom_enroll_for_specific');
        function coursepress_custom_enroll_for_specific( $student_id ) {
        $course_id = ****add course id here****;
        CoursePress_Data_Course::enroll_student( $student_id, $course_id );
    }

    -------

    We were also discussing the Membership specific registration function ms_model_member_create_new_user. Does this function pass the new user's membership level?

    I found this to get current user's membership ID:

    public function get_membership_ids() {
      $result = array();
      foreach ( $this->subscriptions as $subscription ) {
    	$result[] = $subscription->membership_id;
      }
      return $result;
    }

    and then this to return subscription:

    get_subscription( $membership_id );

    Once I know the subscription, I can do a conditional statement to add the user to the correct course.

    function coursepress_custom_enroll_for_specific( $student_id ) {
    
      if ( $subscription == "" ) {
          $course_id = ****add course id here****;
          CoursePress_Data_Course::enroll_student( $student_id, $course_id );
      } else if ( $subscription == "" ) {
          $course_id = ****add course id here****;
          CoursePress_Data_Course::enroll_student( $student_id, $course_id );
      }
    
    }

    Something like this...

    -----------

    I am not super familiar with your Membership or CoursePress code. Is any of this close? Can you fill in the gaps?

    For instance, when I use get_subscription, is that returning an ID, or a string?

    Etc.

    Thanks so much for looking!

  • Ash

    Hello mediastead

    I am sorry for the delay. Looks like you want to auto enroll a member based on his membership. Please use the code from here: https://gist.github.com/bappi-d-great/7ba550e35f1b9250b24cfa383971b1f1

    You just need to set the course array where membership id is index and course id is value.

    You can use this code in your theme's functions.php if the theme is not changed. Otherwise mu-plugin is the best option. To create a mu-plugin, go to wp-content/mu-plugins folder. If there is no mu-plugins folder then, create one. Now, inside the mu-plugins folder create file with name anything.php (make sure file extension is .php). Now start with a <?php tag and then put the above code.

    Hope it helps! Please feel free to ask more questions if you have any.

    Have a nice day!

    Cheers,
    Ash