|
/ Documentation /Developer Hooks & Events/ suredonation_new_donor_user_data Filter Hook

suredonation_new_donor_user_data Filter Hook

Overview

The suredonation_new_donor_user_data filter allows developers to modify the WordPress user data before SureDonation creates a new WordPress account for a donor.

You can use this filter to customize the data passed to wp_insert_user(), such as changing the user’s role, display name, or other supported user fields.

You can also use the filter to prevent the WordPress account from being created.

When to Use This Filter

Use this filter when you need to:

  • Change the default donor WordPress role.
  • Customize the donor’s display name.
  • Modify user information before account creation.
  • Add supported WordPress user fields.
  • Apply custom logic to donor account creation.
  • Prevent a WordPress account from being created.

Filter Signature

apply_filters(   'suredonation_new_donor_user_data',  $user_data,   $donor_id,   $email);

Parameters

ParameterTypeDescription
$user_dataarrayUser data that will be passed to wp_insert_user().
$donor_idintThe SureDonation donor record ID.
$emailstringEmail address associated with the donor.

$user_data

The array always contains:

KeyDescription
user_loginWordPress username.
user_emailDonor email address.
user_passGenerated WordPress user password.
roleDefault donor role: suredonation_donor.

When the donor’s name is available, the array also includes:

  • first_name
  • last_name
  • display_name

Return Value

Return the modified $user_data array to continue with WordPress user creation.

return $user_data;

To prevent the account from being created, return false or any non-array value.

return false;

When account creation is aborted:

  • No WordPress user is created.
  • suredonation_donor_user_created does not fire.

Basic Usage

add_filter( 'suredonation_new_donor_user_data',  'your_custom_function',  10,  3 );

function your_custom_function( $user_data, $donor_id, $email ) {

    // Modify or inspect $user_data here.

    return $user_data;

}

Example: Change the Donor Role

The following example assigns a custom supporter role instead of the default suredonation_donor role.

add_filter( 'suredonation_new_donor_user_data',  'mysite_donor_role', 10,  3);

function mysite_donor_role( $user_data, $donor_id, $email ) {

    // Give donors a custom role instead of the default.

    $user_data['role'] = 'supporter';

    return $user_data;

}

Example: Customize the Display Name

You can modify the display name before the WordPress account is created.

add_filter(  'suredonation_new_donor_user_data',  'mysite_donor_display_name',  10,    3);

function mysite_donor_display_name( $user_data, $donor_id, $email ) {

    if ( ! empty( $user_data['first_name'] ) ) {

        $user_data['display_name'] = $user_data['first_name'];

    }

    return $user_data;

}

Example: Prevent Account Creation

Return a non-array value to stop SureDonation from creating the WordPress account.

add_filter( 'suredonation_new_donor_user_data', 'mysite_prevent_donor_account', 10, 3);

function mysite_prevent_donor_account( $user_data, $donor_id, $email ) {

    if ( '[email protected]' === $email ) {

        return false;

    }

    return $user_data;

}

In this example, the WordPress account is not created for the specified email address.

User Creation Flow

The filter is part of the donor-to-WordPress-user linking process:

  1. A donor record is processed by SureDonation.
  2. SureDonation checks whether WordPress user creation is enabled.
  3. If a new user needs to be created, the default $user_data array is prepared.
  4. The suredonation_new_donor_user_data filter is applied.
  5. Your callback can modify the user data or abort the process.
  6. If an array is returned, SureDonation passes the data to wp_insert_user().
  7. If a non-array value is returned, account creation is stopped.
  8. When a user is successfully created, the suredonation_donor_user_created action can fire.

Related Hooks

  • suredonation_donor_user_created : Runs after a WordPress user has been successfully created for a donor.
Was this doc helpful?
What went wrong?

We don't respond to the article feedback, we use it to improve our support content.

Need help? Contact Support
Table of Contents
Scroll to Top