WordPress MU Affiliate work. Adding Multi Level, auto activate, etc..


I am working customizing the affiliate plugin for my company.

We do a lot with multi level marketing.

-added function to automatically enable affiliate accounts on activation

-modified new user activation to build the users up line tree

Added new table wp_affiliate_tree as current database schema is not optimal for tracking many levels deep.


CREATE TABLE wp_affiliate_tree (

user_id bigint(20) NOT NULL,

ref_user_id bigint(20) NOT NULL,

lvl mediumint(6) NOT NULL,

PRIMARY KEY (user_id,ref_user_id)

) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT=’affiliate support tree’;

Function to activate new user and create there tree.

function initial_register_affiliate($user_id, $password, $met){


$reference = $user_info->user_login. '-' . strrev(sprintf('%02d', $user_id + 35));

update_usermeta($user_id, 'enable_affiliate', 'yes');

update_usermeta($user_id, 'affiliate_reference', $reference);

update_usermeta($user_id, 'affiliate_hash', 'aff' . md5(AUTH_SALT . $reference));


// If referred by another user_id then build upline tree


global $wpdb;

$sql = $wpdb->prepare( "INSERT IGNORE INTO ".$wpdb->base_prefix."affiliate_tree (user_id, ref_user_id, lvl) VALUES (%d, %d, 1)", $user_id,$refer_user_id );

$queryresult = $wpdb->query($sql);

$sql = $wpdb->prepare( "INSERT IGNORE INTO ".$wpdb->base_prefix."affiliate_tree (user_id, ref_user_id, lvl)

SELECT %d, ref_user_id, lvl+1 FROM ".$wpdb->base_prefix."affiliate_tree WHERE user_id=%d", $user_id, $refer_user_id );

$queryresult = $wpdb->query($sql);



-Adding support for multi level commission levels for the supporter plugin..

under the settings page added a drop down to select the amount of levels to pay on.

From there there will be a list of the level with drop downs to set the rate / percent of commission.

-Adding support for percentage based commission levels.

If is anyone is interested in this work let me know.. or if there is any other or suggestions please feel free to let me know.