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.

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.

  • Mason
    • DEV MAN’s Sidekick

    *Edit* User error - deleted original post.

    Here's jozwikjp's original:

    Here are my notes on this project.

    I am still trying to decide if I want to add transaction data for each time a commission is credited.

    But as it is now. It works and you can create a unlimited depth down line.. And set the commission levels for each level via a percentage drop down.
    I will put it together and upload a zip of the package to my server.. You guys can check it out from there.

  • georgef
    • The Incredible Code Injector


    Very cool, I'll definitely want to take a look at it.

    Only concern would be doing that with Paypal. About a year ago I setup something similar using Amember, but was adviced not to use any multi level (downline) structure with Paypal as a merchant as its against there TOS.

    Not sure if anything's changed and I've seen one/two companies do that.

    You familiar with any of that?

  • jozwikjp
    • The Incredible Code Injector

    I am still working on one this one.. I will be uploading it somewhere as soon as I go through some more testing.

    This will be a percent that is stored in the user_meta table for a selected user.
    This kicker rate is added to the commission rate that is payed on each level.
    For us we have special partners that get additional higher rates.

    As accounts are activated so is there affiliate account.

    Still have to do.
    Payout on recurring payments.
    I have to add a function to pay the commission monthly or as the subscribers are charged.

    Foreseeable issues.
    Since all of our members have affiliate records created in the user_meta fields I have sustainability concerns.

    The affiliate_hash and affiliate_ref records are selected by their values. There is not a index on that long text field.
    And adding a index to that field doesn't really make sense.
    So I am debating create another reference table to lookup this referralids and hashes.

    Additional Commission Payout Options

  • TonyV
    • Site Builder, Child of Zeus

    #1) would like the ability to pay affiliates a recurring monthly compensation for all referrals.

    #2) I think I saw that clickbank will allow for the monthly compensation and I have seen other companies set up subscription through paypal as part of their clickbank advertising system. so I am thinking it might be worth looking into integrating the payment going that route instead of directly through paypal. That way click bank can be used as a marketing tool in the respects of using the affiliates associated with it to advertise our businesses.

    so basically the integration would be through clickbank process for setting up the subscription through paypal, and then clickbank could handle all the commissions to the affiliates which would be slick.

    right now I have a set up that sends payment to paypal, setting up the subscription using pay to blog. Then after payment is made the new register is forwarded to an affiliate site I created to handle all commissions for any new referrals. I did it that way because I have multi tiers, but it is a bit cumbersome not to mention that it's not totally automated.

    I know that would mean that new signups who land directly on the registration page would then be routed through clickbank, which would be ok with me... I would then put a link in their back admin inviting them to sign up for the affiliate program so they can make a commission referring others, and I could send them directly to clickbank to sign up this way... unless you want to go all out and figure a way to integrate that as well.

    I am willing to bet this would be a great setup for many wpmur's I have run into a lot of coach, marketing guru's using wp for membership sites that are set up to capture members, but none that I see are set up to reward the affiliates for referrals. I think it would be a great addition to their options so they can expand on their marketing, In fact I am willing to bet it would drive sales for wpmudev if it were a developed premium plugin. I would be the first to drive marketers I know to it :wink:

    Tony V

  • TonyV
    • Site Builder, Child of Zeus

    I should have mentioned the coach marketers I am referring to are teaching people how to be super affiliates marketing products and services from clickbank. I would love for my business to be one of the services that marketers are marketing for me through clickbank.

    Just my two cents.

    Tony V

  • TonyRLA
    • WPMU DEV Initiate

    Man, I love this site!

    I've been thinking about exactly this type of potential MLM plugin, and of course you guys are already well down the road. I guess great minds think alike. Though apparently mine's a touch slower than the rest of you. So what's the status on this? Is there somewhere I can get the modded plug-in to test?

    My concept is for a white-labeled on-line solution for the typical vitamin or self-help MLM scheme. Typically MLM affiliates each get their own "website" which refers traffic to a SuperAdmin site where they sell their product and sign-up downline affiliates. I was thinking that it would be easy enough to use the Marketplace Plugin to handle this sales aspect on the SuperAdmin site, plus something like this mod of the Affiliate Plugin for the commission tree.

    I like TonyV's clickbank concept very much for an MLM that selling clicks or site referrals, but for the typical vitamin MLM I'm not sure clickbank would work. Those type of MLM's usually pay-out straight from their banks either in paper checks or via direct deposit. So for my concept, all that's required for pay-out management would be just for the SuperAdmin to be able generate a csv of periodic monthly or weekly commissions payable that can then be imported to Quickbooks or whatever accounting program to handle the bookkeeping.

    I didn't know about a PayPal TOS issue. I'll take a look at it. I was already thinking that online payment was going to be the most problematic aspect for me because of PayPal's high fees, and because in the case of your typical vitamin MLM, sales are often closed face-to-face. I was thinking for face to face sales affiliates would have to collect checks and credit card numbers and mail them in as they do normally nowadays, but I'd sure appreciate any better suggestions.

    What do you guys think? And if someone could please point me to the modded affiliates plugin, I'll play with it and swing back with more thoughts.



  • joepro
    • New Recruit

    I am one of those super affiliates, in fact, one of the very first in the Clickbank Apex Club for top 5% of earners. I want a wpmu system for my new network marketing company. It needs to create a child blog in mu, replicate a template, and ideally manage all the transaction data. If the transaction data cannot be handled, I will use another platform and run the replication system as a membership site. Any help for hire on this.


    Ron Davies CD, MBA

  • TonyRLA
    • WPMU DEV Initiate

    Hi Ron/JoePro,

    I'm working on on a configuration that does most of what you're talking about. The missing part is this back office residual stream aspect. I've got a developer who is assessing the mods to make everything work. If you're interested in getting in touch with me, I think you can send me a private message via this site If this site doesn't have PM-ing enabled, leave a post here, and we'll figure out a way to get in touch.

    Any status update on the mods that this thread was originally about? Or did the OP go on to other work?



  • twicealive
    • The Incredible Code Injector

    Hi Joe,

    I like the work you are doing on the Affiliate Plugin.

    Have you added other things as well? Such as Multiple levels (10) and width (unlimited?) in a matrix, and payment settings %/$ for each level. It would be nice if we could setup several different matrix's each with different payment scenarios and assign membership or supporter levels to the certain price structure: that way we could setup different payout structures for affiliates who are also paid members of various levels. How about the ability to have a forced matrix, or not?

    I'll try to reach you on your website, I'd love to try out your advancements.

    Best Regards,

  • misyte
    • Design Lord, Child of Thor

    I'm also very interested in this project. We need multi-levels of affiliates as well as residuduals. Do you know if the payments can be handled automatically, before they hit the gateway, paypal, or otherwise? Then everyone is kept "honest".



  • greg_mcewan_marriott
    • The Incredible Code Injector

    yep would love this too, did anything come of this?
    I would love to be able to "track" a members downtree, as in member A recruits member A1, A2, A3

    I would like to be able to track 5 levels down if possible - am rtunning membership premium and affiliate - ANY chance of this happening - i will pay for it

    • Site Builder, Child of Zeus


    if I can be of any help, just write to me. I am interested into this type of development.

    I tried wpbinarymlm but there's no ranks. I need to control the users by giving them some ranks like bronze, silver, gold, etc. and depending this rank to allow them to buy some products in the e-shop.

    What about the activation / deactivation rules. To have some panels to enter some conditions to validate, to promote, to upgrade and cronjobs to trigger them.

    • Vinod Dalvi
      • WP Unicorn


      Welcome to the WPMU Dev community and thanks for posting on the forums.

      Glad to see you are interested in the development. You can develop a solution and post it on this foru, if you want to share it with others.

      Your help is really appreciated and i hope it will help others.

      Thank you for being a WPMU DEV member and have a great day!

      Vinod Dalvi

  • TonyV
    • Site Builder, Child of Zeus

    I am very surprised that with this much interest in this type of plugin it has not been done yet. I was told last year that if I posted a request for development of a tool that would be useful to all and every one chimed in that more than likely it would be done. Well, I see lots of people chimed in, but no takers on development. Surely its not too hard for any of the developers at wpmudev after all I have seen them do up to this point. So I am confused. My vote is still, lets do this thing. You have all we need above.
    Thanks for being the great developers you are. :slight_smile:

    Tony V

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.