Add fields to csv export Membership +

I am trying to export the user profile fields created in buddypress

/wp-admin/users.php?page=bp-profile-setup

How can I export the users First Name, Last Name, Membership Type, Email, Address, City, State, Zip, and Phone.

I have granted support staff user access for this website.

Thanks,
William

  • Michael Bissett

    Hey @William, hope you're doing well today!

    You can try using a plugin like this to handle the exporting of all those fields & metadata:

    https://wordpress.org/plugins/export-user-data/

    As for the importing of it into another site, you could try this:

    https://wordpress.org/plugins/add-user-metadata/

    Though I should note that while the information from Membership may get copied over correctly, if any of your users are using PayPal to purchase subscriptions, your subscribers may need to purchase a new subscription on the site that they're being migrated to (given the way that PayPal works with this sort of setup).

    Hope this helps!

    Kind Regards,
    Michael

  • William

    Hi @Michael Bissett

    I may not have asked my question correctly. I want to export the data from the Events+ plugin so I can have a master copy of users/attendees that will be attending the event. I am not exporting to another site.

    In the events+ plugin there is a Export link under "Event RSVPs" I would like to export the fields above into this spreadsheet.

    The plugin is currently only exporting User ID, User Name, User Email, Attending, Ticket Count, and Payment Status.

  • Ash

    Hello @William

    To include membership subscription name, please use the following code:

    add_filter( 'eab-exporter-csv-row', 'add_more_data', 99, 4 );
    function add_more_data( $arr, $event, $booking, $user_data ) {
    
    	$factory              = Membership_Plugin::factory();
    	$user_object         = $factory->get_member($user_data->id);
    	$usersubs = $user_object->get_subscription_ids();
    
    	$rows = array();
    	foreach ((array) $usersubs as $key) {
    		if (!empty($key)) {
    			$sub = $factory->get_subscription($key);
    			if (!empty($sub)) {
    				$rows[] = $sub->sub_name();
    			}
    		}
    	} //end foreach
    
    	$arr['Membership Type'] = implode(", ", $rows);;
    	return $arr;
    }

    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.

    Currently buddypress xprofile fields can't be imported. I am sending this to attention of the developer.

    Cheers
    Ash

  • Hoang Ngo

    Hi there,

    I have modify the code Ash provided above a little bit, it should work.

    add_filter('eab-exporter-csv-row', 'add_more_data', 99, 4);
    function add_more_data($arr, $event, $booking, $user_data)
    {
        global $bp;
        $factory = Membership_Plugin::factory();
        $user_object = $factory->get_member($user_data->id);
        $usersubs = $user_object->get_subscription_ids();
    
        $rows = array();
        foreach ((array)$usersubs as $key) {
            if (!empty($key)) {
                $sub = $factory->get_subscription($key);
                if (!empty($sub)) {
                    $rows[] = $sub->sub_name();
                }
            }
        } //end foreach
        $bp_fields = array(
            'First Name',
            'Last Name',
            'Email',
            'Address',
            'City',
            'State',
            'Zip',
            'Phone'
        );
        global $wpdb;
        foreach ($bp_fields as $field) {
            $sql = "SELECT data.value FROM <code>wp_bp_xprofile_data</code> data, <code>wp_bp_xprofile_fields</code> fields
    WHERE data.<code>field_id</code> = fields.id AND fields.name =%s AND data.<code>user_id</code>=%d";
            $result = $wpdb->get_var($wpdb->prepare($sql, $field, get_current_user_id()));
            $arr[$field] = $result;
        }
    
        $arr['Membership Type'] = implode(", ", $rows);
    
        return $arr;
    }

    Please give it a try and let us update.

    Best regards,
    Hoang Ngo

  • William

    Hi @Hoang Ngo,

    I have updated the code to my functions.php file. When I run the export the custom/new columns are blank ( First Name, Last Name, Email, Address, City, State, Zip and Phone are exporting blank columns).

    The old columns are still working (User ID, User Name, User Email, Attending, Ticket Count, Payment Status and Membership Type).

    Attached is a screen shot. I have also re-granted support staff user access for this website.

    Thanks,
    William

  • Hoang Ngo

    Hi @William,

    I hope you are well today.

    The staff access token seem expired, also, I will need to check your database too. Can you please send in:

    - Mark to my attention - ATTN: Hoang Ngo
    - Link back to this thread
    - Include admin/network access
    - Include cPanel (I will need to look at the DB so need PHPMyAdmin or similar)
    - Include FTP
    - Include any relevant URLS for your site

    On the contact form, select "I have a different question", this ensures it comes through and gets assigned to me.

    Thanks!!.

    Best regards,
    Hoang Ngo

  • Hoang Ngo

    Hi there,

    I hope you are well today.

    Many thanks for your information. I've just updated the code to

    add_filter('eab-exporter-csv-row', 'add_more_data', 99, 4);
    function add_more_data($arr, $event, $booking, $user_data)
    {
        global $bp;
        $factory = Membership_Plugin::factory();
        $user_object = $factory->get_member($user_data->id);
        $usersubs = $user_object->get_subscription_ids();
    
        $rows = array();
        foreach ((array)$usersubs as $key) {
            if (!empty($key)) {
                $sub = $factory->get_subscription($key);
                if (!empty($sub)) {
                    $rows[] = $sub->sub_name();
                }
            }
        } //end foreach
        $bp_fields = array(
            1 => 'First Name',
            6 => 'Last Name',
            2 => 'Address',
            3 => 'City',
            4 => 'State',
            5 => 'Zip',
            7 => 'Phone'
        );
        global $wpdb;
        foreach ($bp_fields as $key=>$field) {
            $sql = "SELECT data.value FROM <code>wp_bp_xprofile_data</code> data, <code>wp_bp_xprofile_fields</code> fields
    WHERE data.<code>field_id</code> = fields.id AND fields.id =%d AND data.<code>user_id</code>=%d";
            $result = $wpdb->get_var($wpdb->prepare($sql, $key, get_current_user_id()));
            $arr[$field] = $result;
        }
    
        $arr['Membership Type'] = implode(", ", $rows);
    
        return $arr;
    }

    And it's working now, please check

    Best regards,
    Hoang Ngo