Example #1
0
function eMember_handle_affiliate_signup($user_name, $pwd, $afirstname, $alastname, $aemail, $referrer)
{
    global $wpdb;
    $emember_config = Emember_Config::getInstance();
    if (function_exists('wp_aff_platform_install')) {
        $members_table_name = $wpdb->prefix . "wp_eMember_members_tbl";
        $query_db = $wpdb->get_row("SELECT * FROM {$members_table_name} WHERE user_name = '{$user_name}'", OBJECT);
        if ($query_db) {
            $eMember_id = $query_db->member_id;
            $membership_level = $query_db->membership_level;
            $allowed_levels = $emember_config->getValue('wp_eMember_affiliate_account_restriction_list');
            //example value "1,2,3";
            if (!empty($allowed_levels)) {
                //check if this level should be allowed to have an affiliate account
                $pieces = explode(",", $allowed_levels);
                if (!in_array($membership_level, $pieces)) {
                    //no permission for affilaite account creation
                    return;
                }
            }
            $commission_level = get_option('wp_aff_commission_level');
            //This must use the get_option and not getValue
            $date = date("Y-m-d");
            wp_aff_create_affilate($user_name, $pwd, '', '', $afirstname, $alastname, '', $aemail, '', '', '', '', '', '', '', '', $date, '', $commission_level, $referrer);
            wp_aff_send_sign_up_email($user_name, $pwd, $aemail);
        } else {
            echo "<br />Error! This username does not exist in the member database!";
        }
    }
}
function eStore_handle_auto_affiliate_account_creation($payment_data)
{
    if (function_exists('wp_aff_platform_install') || function_exists('wp_aff_create_affilate')) {
        eStore_payment_debug('Checking if auto affiliate account creation feature is active.', true);
        $create_auto_affiliate_account = get_option('eStore_create_auto_affiliate_account');
        if ($create_auto_affiliate_account) {
            eStore_payment_debug('Checking if an affiliate account already exists...', true);
            if (function_exists('wp_aff_check_if_account_exists')) {
                $account_exists = wp_aff_check_if_account_exists($payment_data['payer_email']);
            } else {
                eStore_payment_debug('Error! You need to update the affiliate platform plugin to use the auto upgrade feature!', false);
            }
            if (!$account_exists) {
                $aff_id = uniqid();
                $pwd = $aff_id;
                //use the affiliate ID as the password to create the account
                $commission_level = get_option('wp_aff_commission_level');
                $date = date("Y-m-d");
                eStore_payment_debug('Creating affiliate account with Affiliate ID:' . $aff_id, true);
                wp_aff_create_affilate($aff_id, $pwd, $payment_data['payer_business_name'], "", $payment_data['first_name'], $payment_data['last_name'], "", $payment_data['payer_email'], "", "", "", "", "", $payment_data['address_country'], "", "", $date, $payment_data['payer_email'], $commission_level, "");
                wp_aff_send_sign_up_email($aff_id, $pwd, $payment_data['payer_email']);
            } else {
                eStore_payment_debug('Affiliate account already exists with this email address. No new account will be created.', true);
            }
        }
    } else {
        eStore_payment_debug('WP Affiliate Platform capability is not present.', true);
    }
}