how do I export membership users?

I want to export the registered users to .csv (or comparable), including their membership levels. The export option only seemed to cover content, not users so I dont know where to begin.

  • Ash
    • WordPress Hacker

    Hello @Edgar

    I hope you are well today and thanks for asking the question.

    Currently, there is no way to export members from membership. But I believe this would be a nice feature. I am marking this thread as a feature request.

    Cheers
    Ash

  • Zeus
    • Site Builder, Child of Zeus

    Any update to this. I have a client asking me to export a list of current subscribers and I'm not sure if this is an option? Or at least instructions on how to provide a listing of subscribers.

    Thanks WPMUDEV

  • Ash
    • WordPress Hacker

    Hello @Bryan

    This feature is marked as a request and a request is considered to developer when we see interest from more members on that feature.

    Currently I can give you some code to show a list of members in front end or back end, but that can't be exported, you can just see them. Please let me know if that will help and I will write the code for you.

    Have an awesome day!

    Cheers
    Ash

  • Ash
    • WordPress Hacker

    Hi there

    Please try the following code:

    add_shortcode( 'show_all_m2_members', 'show_all_m2_members' );
    function show_all_m2_members() {
        $members = MS_Model_Member::get_members();
        $html = '<table>';
        $html .= '<tr>';
            $html .= '<th>Username</th>';
            $html .= '<th>Display name</th>';
        $html .= '</tr>';
        foreach( $members as $member ) {
            if( $member->has_membership() ) {
                $user = $member->get_user();
                $html .= '<tr>';
                    $html .= '<td>';
                        $html .= $user->user_login;
                    $html .= '</td>';
                    $html .= '<td>';
                        $html .= $user->display_name;
                    $html .= '</td>';
                $html .= '</tr>';
            }
        }
        $html .= '</table>';
    
        return $html;
    }

    You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name 'mu-plugins'. If there is no folder in that name, then create a folder, name it 'mu-plugins', create a file inside that, give any name you like and paste the code in there. You don't need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always. If you use mu-plugins then add a php start tag at the beginning of the code.

    The use the following shorcode in any page:

    [show_all_m2_members]

    Hope it helps :slight_smile: Please feel free to ask more question if you have any.

    Cheers
    Ash

  • Ash
    • WordPress Hacker

    Hello Zeus

    The code above fetch only the active members, so the status will always be active. I have modified the code to show membership names only, please give a try.

    add_shortcode( 'show_all_m2_members', 'show_all_m2_members' );
    function show_all_m2_members() {
        $members = MS_Model_Member::get_members();
        $html = '<table>';
        $html .= '<tr>';
            $html .= '<th>Username</th>';
            $html .= '<th>Display name</th>';
            $html .= '<th>Email</th>';
            $html .= '<th>Membership Name</th>';
        $html .= '</tr>';
        foreach( $members as $member ) {
            if( $member->has_membership() ) {
                $memberships = array();
                $subscriptions = $member->subscriptions;
                foreach( $subscriptions as $subscription )
                {
                    $membership = MS_Factory::Load( 'MS_Model_Membership', $subscription->membership_id );
                    array_push( $memberships, $membership->name );
                }
    
                $user = $member->get_user();
                $html .= '<tr>';
                    $html .= '<td>';
                        $html .= $user->user_login;
                    $html .= '</td>';
                    $html .= '<td>';
                        $html .= $user->display_name;
                    $html .= '</td>';
                    $html .= '<td>';
                        $html .= $user->user_email;
                    $html .= '</td>';
                    $html .= '<td>';
                        $html .= implode( ', ', $memberships );
                    $html .= '</td>';
                $html .= '</tr>';
            }
        }
        $html .= '</table>';
    
        return $html;
    }

    Hope it helps :slight_smile: Please feel free to ask more question if you have any.

    Cheers
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.