slicewp_get_affiliate_by_user_email()

Description

Retrieves an affiliate from the database by the given user’s email. Because an affiliate must also have a corresponding WP_User and the email address for users in a WordPress installation is always unique, you can retrieve an affiliate by using the user’s email address.

Parameters

slicewp_get_affiliate_by_user_email( $user_email );
  • $user_email (string)(required) The email address of the user associated with the affiliate.

Return

(SliceWP_Affiliate|null) A SliceWP_Affiliate object containing the affiliate data, or null if there is no affiliate data associated with the user that has the provided email address.

Example

The following example shows how you can retrieve the affiliate data object corresponding to the user that has the email address “john_doe@johndoe.com”.

$affiliate = slicewp_get_affiliate_by_user_email( 'john_doe@johndoe.com' );
// Returned value.

SliceWP_Affiliate Object
(
    [id:protected] => 10
    [user_id:protected] => 22
    [date_created:protected] => 2021-08-26 10:48:22
    [date_modified:protected] => 2021-08-26 10:48:22
    [status:protected] => active
    [payment_email:protected] => john_doe@johndoe.com
    [website:protected] => https://johndoe.com/
)

Because the SliceWP_Affiliate object’s properties are protected, to access them you can use the get( $property_name ) method.

$affiliate = slicewp_get_affiliate_by_user_email( 'john_doe@johndoe.com' );

if ( ! is_null( $affiliate ) ) {

    $user_id = $affiliate->get( 'user_id' );
    $status  = $affiliate->get( 'status' );

}

Was this article helpful?

Do you have any feedback or suggestions to improve this page?

Can't find what you're looking for? We're here to help.

Open a support ticket