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

From aMember Pro Documentation
Jump to: navigation, search
 
Line 1: Line 1:
 
Add this code to [[site.php file]]:
 
Add this code to [[site.php file]]:
 
<source>
 
<source>
Am_Di::getInstance()->hook->add(Am_Event::USER_AFTER_INSERT, 'userAfterInsert');
+
Am_Di::getInstance()->hook->add(Am_Event::USER_AFTER_INSERT, function (Am_Event $e){
function userAfterInsert(Am_Event $e){
+
 
     $user = $e->getUser();
 
     $user = $e->getUser();
 
     if($user->data()->get('created-by-plugin')){
 
     if($user->data()->get('created-by-plugin')){
Line 13: Line 12:
 
         $access->insert();
 
         $access->insert();
 
     }
 
     }
}
+
});
 
</source>
 
</source>
  
 
Each time when user will be create by integration plugin, aMember will add free lifetime subscription to product 1 for that user.
 
Each time when user will be create by integration plugin, aMember will add free lifetime subscription to product 1 for that user.

Latest revision as of 05:05, 5 February 2016

Add this code to site.php file:

Am_Di::getInstance()->hook->add(Am_Event::USER_AFTER_INSERT, function (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.