Our website is running on a shared Linux host using Wordpress with the MailPoet plugin to keep track of newsletter subscribers. We need to modify the plugin so that it keeps track of referral codes.
Current Website Behavior
----------------------------------------
1. User enters email address to subscribe: MailPoet generates a user_id for the user, stores the user_id and email address in the MySQL table wp_wysija_user, tells the user "Check your email inbox..." then sends a confirmation email that contains a confirmation URL.
2. User enters an email address to subscribe that is already in the table but not yet confirmed: MailPoet tells the user "Check your email inbox..." and resends a confirmation email.
3. User clicks on the confirmation URL: Website says “Thank you for subscribing.”
4. User clicks a 2nd or 3rd time on the confirmation URL: Website says “Thank you for subscribing.”
5. User enters an email address to subscribe that is already in the table and already confirmed: Website says "Already subscribed."
Desired New Behavior
-----------------------------------
Situation 1: Same as current behavior, but website also stores a referred_by code, if one exists. See below.
Situation 2: Same as current behavior.
Situation 3: Same as current behavior, but website also generates and stores a new unique referrer code for the user, and displays a webpage with info about the referral program and the user's referral URL. See below.
Situation 4: Same as current behavior, but website displays info about the referral program and the user's referral URL.
Situation 5: Same as current behavior, but website displays info about the referral program and the user's referral URL.
Implementation Details
-------------------------------------
The website has two new MySQL tables (these have already been trivially added):
(a) cc_refer_ids with columns int primary key user_id, varchar refer_id unique
(b) cc_referred_by with columns int primary key user_id, varchar referred_by
Subscription confirmation needs to generate a new random 12 letter refer_id, make sure it is unique, then store it in the cc_refer_ids table, and tell it to the user in URL form.
Clicking referral URL needs to store the URL’s referral ID in a cookie or URL param.
New subscription request needs to credit the referrer by storing the referrer’s ID in the cc_referred_by table.
The freelancer is expected to provide PHP files that implement the above behavior for a website using the latest version of Wordpress and MailPoet.