How to add free access to user who was created by "Protection Plugin" using "Create aMember Users By Demand" function

From aMember Pro Documentation
Revision as of 03:41, 9 August 2013 by Caesar (Talk | contribs)

Jump to: navigation, search

Add this code to site.php file:

<?php
Am_Di::getInstance()->hook->add(Am_Event::USER_AFTER_INSERT, 'userAfterInsert'); 
function userAfterInsert(Am_Event $e){
    $user = $e->getUser();
    if($user->data()->get('created-by-plugin')){
        // Add free access to user who was created by integration plugin: 
        $access = Am_Di::getInstance()->accessRecord;
        $access->product_id = 1; // Change to actual product;
        $access->begin_date = Am_Di::getInstance()->sqlDate;
        $access->expire_date = MAX_SQL_DATE; // Change to actual expiration date
        $access->user_id = $user->user_id;
        $access->insert();
    }
}

Each time when user will be create by integration plugin, aMember will add free lifetime subscription to product 1 for that user.