Action
uncanny-automator-pro
esaf-process-signup
Fires after a user successfully signs up via the Easy Affiliate plugin, providing access to user data.
add_action( 'esaf-process-signup', $callback, 10, 1 );
Description
Fired after a new Easy Affiliate user is created and stored, this hook provides access to the `$user` object. Developers can use this to extend the signup process, perhaps by updating custom user meta or triggering additional integrations based on affiliate creation.
Usage
add_action( 'esaf-process-signup', 'your_function_name', 10, 1 );
Parameters
-
$user(mixed) - This parameter contains the user object or user ID that is being processed during the signup.
Examples
/**
* Example of how to hook into the 'esaf-process-signup' action.
* This function will be triggered after a new affiliate is processed and stored.
* It demonstrates how to access the affiliate user object and potentially perform additional actions.
*
* @param object $user The user object representing the newly processed affiliate.
*/
function my_esaf_affiliate_signup_handler( $user ) {
// Check if the $user object is valid and has an ID.
if ( ! $user || ! isset( $user->ID ) ) {
error_log( 'esaf-process-signup hook received an invalid user object.' );
return;
}
// You can access various properties of the user object here.
// For example, let's log the affiliate's username and display name.
$username = $user->user_login;
$display_name = $user->display_name;
error_log( sprintf( 'New Easy Affiliate signup processed: Username - %s, Display Name - %s', $username, $display_name ) );
// Example: If you wanted to add custom meta data to the affiliate user upon signup.
// You would need to ensure these fields are actually available on the $user object
// or that you have a way to retrieve them based on the signup context.
// For demonstration purposes, let's assume we have some custom data.
$custom_data = array(
'referred_by_affiliate' => 'some_affiliate_id', // Replace with actual logic to get referrer
'signup_source' => 'website_form', // Replace with actual logic to determine source
);
foreach ( $custom_data as $meta_key => $meta_value ) {
update_user_meta( $user->ID, $meta_key, $meta_value );
error_log( sprintf( 'Added custom meta "%s": "%s" for user ID %d', $meta_key, $meta_value, $user->ID ) );
}
// You could also trigger other external services or internal WP functions here.
// For instance, sending a welcome email via a different method if needed,
// or adding the user to a specific mailing list.
// Example: Triggering another custom action.
do_action( 'my_custom_affiliate_welcome', $user->ID );
}
// Hook into the 'esaf-process-signup' action.
// The third parameter '1' indicates that our callback function expects 1 argument.
// Adjust the priority (e.g., 10, 20) as needed for your specific use case.
add_action( 'esaf-process-signup', 'my_esaf_affiliate_signup_handler', 10, 1 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
uncanny-automator-pro/src/integrations/easy-affiliate/actions/esaf-add-affiliate.php:228
protected function process_action( $user_id, $action_data, $recipe_id, $args, $parsed ) {
$aff = array();
$aff['first_name'] = isset( $parsed['first_name'] ) ? sanitize_text_field( $parsed['first_name'] ) : '';
$aff['last_name'] = isset( $parsed['last_name'] ) ? sanitize_text_field( $parsed['last_name'] ) : '';
$aff['_wafp_user_user_login'] = isset( $parsed['_wafp_user_user_login'] ) ? sanitize_text_field( $parsed['_wafp_user_user_login'] ) : '';
$aff['_wafp_user_user_email'] = isset( $parsed['_wafp_user_user_email'] ) ? sanitize_text_field( $parsed['_wafp_user_user_email'] ) : '';
$aff['wafp_paypal_email'] = isset( $parsed['wafp_paypal_email'] ) ? sanitize_text_field( $parsed['wafp_paypal_email'] ) : '';
$aff['_wafp_user_user_pass'] = isset( $parsed['_wafp_user_user_pass'] ) ? sanitize_text_field( $parsed['_wafp_user_user_pass'] ) : '';
$aff['wafp_user_address_one'] = isset( $parsed['wafp_user_address_one'] ) ? sanitize_text_field( $parsed['wafp_user_address_one'] ) : '';
$aff['wafp_user_address_two'] = isset( $parsed['wafp_user_address_two'] ) ? sanitize_text_field( $parsed['wafp_user_address_two'] ) : '';
$aff['wafp_user_city'] = isset( $parsed['wafp_user_city'] ) ? sanitize_text_field( $parsed['wafp_user_city'] ) : '';
$aff['wafp_user_zip'] = isset( $parsed['wafp_user_zip'] ) ? sanitize_text_field( $parsed['wafp_user_zip'] ) : '';
$aff['wafp_user_country'] = isset( $parsed['wafp_user_country'] ) ? sanitize_text_field( $parsed['wafp_user_country'] ) : '';
$send_notification = isset( $parsed['send_notification'] ) ? sanitize_text_field( $parsed['send_notification'] ) : '';
$send_notification = ( 'true' === $send_notification ) ? true : false;
$user = new User();
$wp_user = get_user_by_email( $aff['_wafp_user_user_email'] );
if ( $wp_user ) {
$is_user_affiliate = get_user_meta( $wp_user, 'wafp_is_affiliate', true );
if ( isset( $is_user_affiliate ) && true === $is_user_affiliate ) {
$action_data['do-nothing'] = true;
$action_data['complete_with_errors'] = true;
$message = sprintf( __( 'The user is already an affiliate - %s', 'uncanny-automator-pro' ), $aff['_wafp_user_user_email'] );
Automator()->complete->action( $user_id, $action_data, $recipe_id, $message );
return;
}
$user->ID = $wp_user->ID;
}
$user->load_from_sanitized_array( $aff );
$user->is_affiliate = true;
$affiliate_id = $user->store();
do_action( 'esaf-process-signup', $user );
$user->send_account_notifications( true, $send_notification );
$this->hydrate_tokens(
array( 'affiliate_ID' => $affiliate_id )
);
Automator()->complete->action( $user_id, $action_data, $recipe_id );
}