frontend_model_listsubscriber_aftersave
Yii::app()->hooks->addAction('frontend_model_listsubscriber_aftersave', function($subscriber){
// make sure we only trigger this in the ListsController::actionSubscribe
if (Yii::app()->getController()->getRoute() != 'lists/subscribe') {
return;
}
// if this is not a new record, we stop
if (!$subscriber->getIsNewRecord()) {
return;
}
// do whatever you wish with $subscriber
});
Thank you. Two questions.Each model, be it list subscriber, user, customer, etc, has a set of hooks defined for when they are saved, validated, etc.
For list subscriber, the hook name you are looking for is:
But keep in mind this is triggered absolutely each time when a subscriber is saved, be it a new record or an existing record.Code:frontend_model_listsubscriber_aftersave
So in your case, you could do something like:
The above is not tested, but should give you an idea at least.PHP:Yii::app()->hooks->addAction('frontend_model_listsubscriber_aftersave', function($subscriber){ // make sure we only trigger this in the ListsController::actionSubscribe if (Yii::app()->getController()->getRoute() != 'lists/subscribe') { return; } // if this is not a new record, we stop if (!$subscriber->getIsNewRecord()) { return; } // do whatever you wish with $subscriber });
Sure, accessingIs it possible to get list information in the function as well, in addition to the subscriber?
$list = $subscriber->list;
The above is only triggered for the frontend area. For api you have more control since you do that programatically anyway.Also, is this triggered only when a user subscribers through a form or also when through API?
Thank you, sir.Sure, accessing
Gives you the list.PHP:$list = $subscriber->list;
The above is only triggered for the frontend area. For api you have more control since you do that programatically anyway.
$subscriber->getIsConfirmed();
// or
$subscriber->getIsBlacklisted();