BuddyPress Member Export Import – Hooks & Filters Reference

Export Hooks

Action Hooks

bpxp_before_export_process

Fires before the export process begins.

Parameters:

  • $user_ids (array) – Array of user IDs to be exported
  • $fields (array) – Array of field names to be exported
  • $options (array) – Export options array

Example:

add_action('bpxp_before_export_process', function($user_ids, $fields, $options) {
    // Log export start
    error_log('Starting export of ' . count($user_ids) . ' users');

    // Increase memory limit for large exports
    if (count($user_ids) > 10000) {
        ini_set('memory_limit', '512M');
    }
}, 10, 3);

bpxp_after_export_process

Fires after the export process completes.

Parameters:

  • $total_users (int) – Total number of users exported
  • $fields (array) – Array of fields that were exported

Example:

add_action('bpxp_after_export_process', function($total_users, $fields) {
    // Log export completion
    error_log('Export completed: ' . $total_users . ' users exported');

    // Send notification
    wp_mail(get_option('admin_email'), 'Export Complete', 'Exported ' . $total_users . ' users');
}, 10, 2);

bpxp_before_export_batch

Fires before processing each batch during export.

Parameters:

  • $batch_users (array) – Array of user IDs in current batch
  • $batch_index (int) – Current batch index
  • $total_batches (int) – Total number of batches

Example:

add_action('bpxp_before_export_batch', function($batch_users, $batch_index, $total_batches) {
    // Log batch progress
    error_log(sprintf('Processing batch %d of %d', $batch_index + 1, $total_batches));
}, 10, 3);

UI Action Hooks

bpxp_before_export_select_user

Fires before the user selection dropdown in export UI.

Example:

add_action('bpxp_before_export_select_user', function() {
    echo '<div class="custom-notice">Select users to export</div>';
});

bpxp_after_export_select_user

Fires after the user selection dropdown in export UI.

bpxp_before_export_fields_group

Fires before the field group selection in export UI.

bpxp_after_export_fields_group

Fires after the field group selection in export UI.

bpxp_before_export_prof_fields

Fires before the individual field selection in export UI.

bpxp_after_export_prof_fields

Fires after the individual field selection in export UI.

bpxp_after_export_buttons

Fires after the export button in export UI.

Import Hooks

Action Hooks

bpxp_before_import_process

Fires before the import process begins.

Parameters:

  • $csv_data (array) – CSV data to be imported
  • $field_mapping (array) – Field mapping configuration
  • $options (array) – Import options

Example:

add_action('bpxp_before_import_process', function($csv_data, $field_mapping, $options) {
    // Validate CSV data
    if (count($csv_data) > 10000) {
        // Increase execution time for large imports
        set_time_limit(600);
    }

    // Log import start
    error_log('Starting import of ' . count($csv_data) . ' records');
}, 10, 3);

bpxp_after_import_process

Fires after the import process completes.

Parameters:

  • $results (array) – Import results array
  • $field_mapping (array) – Field mapping used
  • $options (array) – Import options used

Example:

add_action('bpxp_after_import_process', function($results, $field_mapping, $options) {
    // Send summary email
    $message = sprintf(
        'Import Complete: %d created, %d updated, %d errors',
        count($results['created']),
        count($results['updated']),
        count($results['error_messages'])
    );

    wp_mail(get_option('admin_email'), 'Import Summary', $message);
}, 10, 3);

bpxp_before_user_import

Fires before a user is created or updated during import.

Parameters:

  • $user_data (array) – User data being imported
  • $is_update (bool) – True if updating, false if creating

Example:

add_action('bpxp_before_user_import', function($user_data, $is_update) {
    if (!$is_update) {
        // Log new user creation
        error_log('Creating new user: ' . $user_data['user_login']);
    }
}, 10, 2);

bpxp_after_user_import

Fires after a user has been created or updated during import.

Parameters:

  • $user_id (int) – ID of the created/updated user
  • $user_data (array) – User data that was imported
  • $is_update (bool) – True if updated, false if created

Example:

add_action('bpxp_after_user_import', function($user_id, $user_data, $is_update) {
    if (!$is_update) {
        // Add new user to default group
        groups_join_group(array(
            'group_id' => 1,
            'user_id' => $user_id
        ));

        // Send welcome email
        wp_mail($user_data['user_email'], 'Welcome!', 'Welcome to our site!');
    }
}, 10, 3);

UI Action Hooks

bpxp_before_import_limit

Fires before the server limits display in import UI.

bpxp_after_import_limit

Fires after the server limits display in import UI.

bpxp_before_import_file

Fires before the file upload section in import UI.

bpxp_after_import_file

Fires after the file upload section in import UI.

bpxp_before_import_update_user

Fires before the “Update Existing Users” option in import UI.

bpxp_after_import_update_user

Fires after the “Update Existing Users” option in import UI.

bpxp_after_import_button

Fires after the import button in import UI.

Filter Hooks

Export Filters

bpxp_export_capability

Filters the capability required for export operations.

Parameters:

  • $capability (string) – Default: ‘manage_options’

Return: (string) Required capability

Example:

add_filter('bpxp_export_capability', function($capability) {
    return 'export_users'; // Require specific capability
});

bpxp_export_batch_size

Filters the batch size for export operations.

Parameters:

  • $batch_size (int) – Default batch size
  • $total_users (int) – Total number of users being exported

Return: (int) Batch size to use

Example:

add_filter('bpxp_export_batch_size', function($batch_size, $total_users) {
    // Adjust batch size based on total users
    if ($total_users > 50000) {
        return 500;
    } elseif ($total_users > 10000) {
        return 1000;
    }
    return 2000;
}, 10, 2);

bpxp_export_core_user_data

Filters core user data before adding to export.

Parameters:

  • $user_fields (array) – User fields array
  • $user_id (int) – User ID
  • $user_data (object) – WP_User object

Return: (array) Modified user fields

Example:

add_filter('bpxp_export_core_user_data', function($user_fields, $user_id, $user_data) {
    // Add registration date
    $user_fields['registered'] = $user_data->user_registered;

    // Add user status
    $user_fields['status'] = get_user_meta($user_id, 'account_status', true);

    return $user_fields;
}, 10, 3);

bpxp_export_excluded_meta_keys

Filters the list of meta keys excluded from export.

Parameters:

  • $excluded_keys (array) – Array of meta keys to exclude

Return: (array) Modified excluded keys

Example:

add_filter('bpxp_export_excluded_meta_keys', function($excluded_keys) {
    // Add custom keys to exclude
    $excluded_keys[] = 'secret_api_key';
    $excluded_keys[] = 'internal_notes';

    // Remove a default exclusion
    $key = array_search('last_activity', $excluded_keys);
    if ($key !== false) {
        unset($excluded_keys[$key]);
    }

    return $excluded_keys;
});

bpxp_export_meta_value

Filters individual meta values during export.

Parameters:

  • $value (mixed) – Meta value
  • $meta_key (string) – Meta key
  • $user_id (int) – User ID

Return: (mixed) Modified value

Example:

add_filter('bpxp_export_meta_value', function($value, $meta_key, $user_id) {
    // Format phone numbers
    if ($meta_key === 'phone') {
        $value = preg_replace('/(\d{3})(\d{3})(\d{4})/', '($1) $2-$3', $value);
    }

    // Encrypt sensitive data
    if ($meta_key === 'ssn') {
        $value = 'XXX-XX-' . substr($value, -4);
    }

    return $value;
}, 10, 3);

bpxp_max_users_display

Filters the maximum number of users to display in dropdown.

Parameters:

  • $limit (int) – Default: 200

Return: (int) Maximum users to display

Example:

add_filter('bpxp_max_users_display', function($limit) {
    return 500; // Show more users in dropdown
});

Import Filters

bpxp_import_capability

Filters the capability required for import operations.

Parameters:

  • $capability (string) – Default: ‘manage_options’

Return: (string) Required capability

Example:

add_filter('bpxp_import_capability', function($capability) {
    return 'import_users'; // Require specific capability
});

bpxp_import_options

Filters import options before processing.

Parameters:

  • $options (array) – Import options array

Return: (array) Modified options

Example:

add_filter('bpxp_import_options', function($options) {
    // Force email notifications
    $options['send_notifications'] = true;

    // Set custom default role
    $options['default_role'] = 'contributor';

    return $options;
});

bpxp_before_create_user

Filters user data before creating new user.

Parameters:

  • $userdata (array) – User data for wp_insert_user
  • $csv_data (array) – Original CSV row data

Return: (array) Modified user data

Example:

add_filter('bpxp_before_create_user', function($userdata, $csv_data) {
    // Generate display name from first and last name
    if (empty($userdata['display_name'])) {
        $userdata['display_name'] = trim($userdata['first_name'] . ' ' . $userdata['last_name']);
    }

    // Set default bio
    if (empty($userdata['description'])) {
        $userdata['description'] = 'Imported user from CSV';
    }

    return $userdata;
}, 10, 2);

bpxp_before_update_user

Filters user data before updating existing user.

Parameters:

  • $userdata (array) – User data for wp_update_user
  • $csv_data (array) – Original CSV row data

Return: (array) Modified user data

Example:

add_filter('bpxp_before_update_user', function($userdata, $csv_data) {
    // Prevent email changes for certain users
    $protected_users = array('admin@example.com', 'support@example.com');
    if (in_array($userdata['user_email'], $protected_users)) {
        unset($userdata['user_email']);
    }

    return $userdata;
}, 10, 2);

bpxp_should_update_user

Determines if an existing user should be updated.

Parameters:

  • $should_update (bool) – Default: true
  • $user_id (int) – User ID
  • $user_data (array) – New user data

Return: (bool) Whether to update the user

Example:

add_filter('bpxp_should_update_user', function($should_update, $user_id, $user_data) {
    // Don't update administrators
    $user = get_user_by('id', $user_id);
    if (in_array('administrator', $user->roles)) {
        return false;
    }

    // Don't update users created in last 24 hours
    $registered = strtotime($user->user_registered);
    if ($registered > strtotime('-24 hours')) {
        return false;
    }

    return $should_update;
}, 10, 3);

AJAX Actions

Export AJAX Actions

wp_ajax_bpxp_get_export_xprofile_fields

Get xProfile fields for selected groups.

Request Parameters:

  • bpxp_field_group_id (array) – Selected group IDs
  • bpxp_fields_nonce (string) – Security nonce

Response: JSON with field HTML

wp_ajax_bpxp_export_xprofile_data

Export member data to CSV.

Request Parameters:

  • bpxpj_bpmember (array) – User IDs to export
  • bpxpj_field_group (array) – Field group IDs
  • bpxpj_xprofile_fields (array) – Field names
  • bpxp_include_standard_fields (bool) – Include standard fields
  • bpxp_include_usermeta (bool) – Include user meta
  • bpxp_members_nonce (string) – Security nonce

Response: CSV file download

wp_ajax_bpxp_search_users

Search users for export selection.

Request Parameters:

  • search_term (string) – Search query
  • bpxp_search_nonce (string) – Security nonce

Response: JSON with user data

Import AJAX Actions

wp_ajax_bpxp_import_header_fields

Parse CSV headers and show field mapping.

Request Parameters:

  • bpxp_csv_header (array) – CSV header columns
  • bpxp_header_nonce (string) – Security nonce

Response: JSON with mapping HTML

wp_ajax_bpxp_import_csv_data

Import CSV data.

Request Parameters:

  • bpxp_csv_file (array) – CSV data
  • bpxpj_field (array) – Field mapping
  • bpxpj_update_user (string) – Update existing users flag
  • bpxpj_counter (int) – Current batch counter
  • bpxp_csv_nonce (string) – Security nonce

Response: JSON with import results

Groups Export AJAX Actions

wp_ajax_bpxp_export_groups_data

Export BuddyPress groups data.

Request Parameters:

  • group_ids (array) – Group IDs to export
  • format (string) – Export format (normalized/grouped)
  • bpxp_groups_nonce (string) – Security nonce

Response: CSV file download

Usage Examples

Complete Export Customization

/**
 * Comprehensive export customization
 */
class My_Export_Customization {

    public function __construct() {
        // Modify export capability
        add_filter('bpxp_export_capability', [$this, 'set_capability']);

        // Adjust batch size
        add_filter('bpxp_export_batch_size', [$this, 'set_batch_size'], 10, 2);

        // Add custom data
        add_filter('bpxp_export_core_user_data', [$this, 'add_custom_data'], 10, 3);

        // Process meta values
        add_filter('bpxp_export_meta_value', [$this, 'process_meta_value'], 10, 3);

        // Log exports
        add_action('bpxp_after_export_process', [$this, 'log_export'], 10, 2);
    }

    public function set_capability($capability) {
        return 'export_members';
    }

    public function set_batch_size($batch_size, $total_users) {
        // Dynamic batch sizing
        if ($total_users > 100000) {
            return 250;
        } elseif ($total_users > 50000) {
            return 500;
        } elseif ($total_users > 10000) {
            return 1000;
        }
        return 2000;
    }

    public function add_custom_data($user_fields, $user_id, $user_data) {
        // Add WooCommerce data
        if (class_exists('WooCommerce')) {
            $customer = new WC_Customer($user_id);
            $user_fields['total_orders'] = wc_get_customer_order_count($user_id);
            $user_fields['total_spent'] = wc_format_decimal($customer->get_total_spent(), 2);
            $user_fields['billing_country'] = $customer->get_billing_country();
        }

        // Add membership data
        if (function_exists('pmpro_getMembershipLevelForUser')) {
            $level = pmpro_getMembershipLevelForUser($user_id);
            $user_fields['membership_level'] = $level ? $level->name : 'None';
        }

        return $user_fields;
    }

    public function process_meta_value($value, $meta_key, $user_id) {
        // Format dates
        if (in_array($meta_key, ['last_login', 'registration_date', 'expiry_date'])) {
            if (is_numeric($value)) {
                $value = date('Y-m-d H:i:s', $value);
            }
        }

        // Mask sensitive data
        if ($meta_key === 'credit_card') {
            $value = 'XXXX-XXXX-XXXX-' . substr($value, -4);
        }

        // Convert arrays to JSON
        if (is_array($value)) {
            $value = json_encode($value);
        }

        return $value;
    }

    public function log_export($total_users, $fields) {
        global $wpdb;

        $wpdb->insert(
            $wpdb->prefix . 'export_logs',
            array(
                'user_id' => get_current_user_id(),
                'export_date' => current_time('mysql'),
                'total_users' => $total_users,
                'fields_exported' => json_encode($fields),
                'ip_address' => $_SERVER['REMOTE_ADDR']
            )
        );
    }
}

new My_Export_Customization();

Complete Import Customization

/**
 * Comprehensive import customization
 */
class My_Import_Customization {

    public function __construct() {
        // Set capability
        add_filter('bpxp_import_capability', [$this, 'set_capability']);

        // Modify import options
        add_filter('bpxp_import_options', [$this, 'set_options']);

        // Validate users before import
        add_filter('bpxp_should_update_user', [$this, 'validate_update'], 10, 3);

        // Process user data
        add_filter('bpxp_before_create_user', [$this, 'process_new_user'], 10, 2);
        add_filter('bpxp_before_update_user', [$this, 'process_existing_user'], 10, 2);

        // Post-import actions
        add_action('bpxp_after_user_import', [$this, 'after_import'], 10, 3);

        // Log imports
        add_action('bpxp_after_import_process', [$this, 'log_import'], 10, 3);
    }

    public function set_capability($capability) {
        return 'import_members';
    }

    public function set_options($options) {
        $options['send_notifications'] = true;
        $options['default_role'] = 'customer';
        $options['create_bp_profile'] = true;
        return $options;
    }

    public function validate_update($should_update, $user_id, $user_data) {
        // Don't update protected users
        $protected_ids = [1, 2, 3]; // Admin IDs
        if (in_array($user_id, $protected_ids)) {
            return false;
        }

        // Check last update time
        $last_update = get_user_meta($user_id, 'last_import_update', true);
        if ($last_update && strtotime($last_update) > strtotime('-1 hour')) {
            return false; // Don't update if updated within last hour
        }

        return $should_update;
    }

    public function process_new_user($userdata, $csv_data) {
        // Generate username if not provided
        if (empty($userdata['user_login'])) {
            $userdata['user_login'] = $this->generate_username($csv_data);
        }

        // Set display name
        $userdata['display_name'] = trim(
            ($csv_data['first_name'] ?? '') . ' ' . ($csv_data['last_name'] ?? '')
        );

        // Add default bio
        $userdata['description'] = 'Member since ' . date('F Y');

        return $userdata;
    }

    public function process_existing_user($userdata, $csv_data) {
        // Preserve certain fields
        $preserve_fields = ['user_pass', 'user_registered'];
        foreach ($preserve_fields as $field) {
            if (isset($userdata[$field])) {
                unset($userdata[$field]);
            }
        }

        // Update last import time
        update_user_meta($userdata['ID'], 'last_import_update', current_time('mysql'));

        return $userdata;
    }

    public function after_import($user_id, $user_data, $is_update) {
        // Add to default BuddyPress group
        if (!$is_update && function_exists('groups_join_group')) {
            groups_join_group(array(
                'group_id' => get_option('bp_default_group_id', 1),
                'user_id' => $user_id
            ));
        }

        // Create WooCommerce customer
        if (!$is_update && class_exists('WooCommerce')) {
            $customer = new WC_Customer($user_id);
            $customer->set_billing_email($user_data['user_email']);
            $customer->save();
        }

        // Trigger welcome sequence
        if (!$is_update) {
            do_action('member_imported', $user_id, $user_data);
        }
    }

    public function log_import($results, $field_mapping, $options) {
        $log_entry = array(
            'timestamp' => current_time('mysql'),
            'user' => wp_get_current_user()->user_login,
            'created' => count($results['created']),
            'updated' => count($results['updated']),
            'errors' => count($results['error_messages']),
            'options' => $options
        );

        // Save to options table
        $logs = get_option('bpxp_import_logs', array());
        array_unshift($logs, $log_entry);
        $logs = array_slice($logs, 0, 100); // Keep last 100 logs
        update_option('bpxp_import_logs', $logs);
    }

    private function generate_username($csv_data) {
        $base = strtolower($csv_data['first_name'] ?? '') .
                strtolower($csv_data['last_name'] ?? '');
        $base = preg_replace('/[^a-z0-9]/', '', $base);

        if (empty($base)) {
            $base = 'user';
        }

        $username = $base;
        $counter = 1;
        while (username_exists($username)) {
            $username = $base . $counter;
            $counter++;
        }

        return $username;
    }
}

new My_Import_Customization();

Best Practices

Performance Optimization

 

  1. Use batch size filters for large datasets
  2. Implement memory management in hooks
  3. Use direct database queries when appropriate
  4. Clear caches before/after operations

Security

  1. Always verify capabilities in filters
  2. Sanitize all data in filters
  3. Validate user permissions
  4. Log sensitive operations

Error Handling

  1. Return WP_Error objects for failures
  2. Log errors for debugging
  3. Provide user-friendly error messages
  4. Implement rollback mechanisms

Testing

  1. Test hooks on staging first
  2. Use small datasets initially
  3. Monitor memory and execution time
  4. Verify data integrity after operations

Support

For hook-specific questions:

  1. Check the Developer Guide
  2. Submit issues on GitHub
  3. Contact support at wbcomdesigns.com
Last updated: September 30, 2025