User Import from WP Existing Subscribers into a Membership


I used to use magic members on this site and now an moving to Membership 2 Pro.

I already have our members in the WP users listed as subscribers.

The question I have is how can I add the existing WP Users to a Membership Plan that I setup in Membership Pro 2?

Just want it to work with their existing login etc.


  • Ash
    • WordPress Hacker

    Hello Cody

    Please try the following code in your theme's functions.php file:

    add_action( 'init', 'assign_membership_on_register', 999 );
    function assign_membership_on_register() {
      $membership_id = 1343;
      $users = get_users( array( 'fields' => array( 'ID' ) ) );
      foreach($users as $user_id){
        $member = MS_Factory::load( 'MS_Model_Member', $user_id );
      	$subscription = $member->add_membership( $membership_id );
      	if ( $member->has_membership() ) {
      		$member->is_member = true;
      	} else {
      		$member->is_member = false;

    You need to set the correct membership ID in the above code.

    Then refresh the site and admin 2-3 times, check if you have all the members added in a membership and then you are good to remove that code.

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

    Have a nice day!


  • Ash
    • WordPress Hacker

    Hello Cody

    Would you please enable debug mode and check if there is any error? To enable debug mode please go to wp-config.php and change

    define( 'WP_DEBUG', false );


    define( 'WP_DEBUG', true );
    define( 'WP_DEBUG_DISPLAY', false );
    define( 'WP_DEBUG_LOG', true );

    That will create a file called debug.log inside wp-content folder. Open that file, check the very bottom and you will see the latest errors. Please send me those.

    Have a nice day!


Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.